您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AppDelegate.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "AppDelegate.h"
  10. #import <React/RCTAssert.h>
  11. #import <React/RCTBundleURLProvider.h>
  12. #import <React/RCTLinkingManager.h>
  13. #import <React/RCTRootView.h>
  14. /**
  15. * A <tt>RCTFatalHandler</tt> implementation which swallows JavaScript errors.
  16. * In the Release configuration, React Native will (intentionally) raise an
  17. * unhandled NSException for an unhandled JavaScript error. This will
  18. * effectively kill the application. <tt>_RCTFatal</tt> is suitable to be in
  19. * accord with the Web i.e. not kill the application.
  20. */
  21. RCTFatalHandler _RCTFatal = ^(NSError *error) {
  22. id jsStackTrace = error.userInfo[RCTJSStackTraceKey];
  23. @try {
  24. NSString *name
  25. = [NSString stringWithFormat:@"%@: %@",
  26. RCTFatalExceptionName,
  27. error.localizedDescription];
  28. NSString *message
  29. = RCTFormatError(error.localizedDescription, jsStackTrace, 75);
  30. [NSException raise:name format:@"%@", message];
  31. } @catch (NSException *e) {
  32. if (!jsStackTrace) {
  33. @throw;
  34. }
  35. }
  36. };
  37. @implementation AppDelegate
  38. // https://facebook.github.io/react-native/docs/linking.html
  39. - (BOOL)application:(UIApplication *)application
  40. continueUserActivity:(NSUserActivity *)userActivity
  41. restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
  42. {
  43. return [RCTLinkingManager application:application
  44. continueUserActivity:userActivity
  45. restorationHandler:restorationHandler];
  46. }
  47. - (BOOL)application:(UIApplication *)application
  48. didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  49. {
  50. #if !DEBUG
  51. // In the Release configuration, React Native will (intentionally) raise an
  52. // unhandled NSException for an unhandled JavaScript error. This will
  53. // effectively kill the application. In accord with the Web, do not kill the
  54. // application.
  55. if (!RCTGetFatalHandler()) {
  56. RCTSetFatalHandler(_RCTFatal);
  57. }
  58. #endif
  59. NSURL *jsCodeLocation
  60. = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios"
  61. fallbackResource:nil];
  62. RCTRootView *rootView
  63. = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
  64. moduleName:@"App"
  65. initialProperties:nil
  66. launchOptions:launchOptions];
  67. // Set a background color which is in accord with the JavaScript and Android
  68. // parts of the application and causes less perceived visual flicker than the
  69. // default background color.
  70. rootView.backgroundColor
  71. = [[UIColor alloc] initWithRed:.07f green:.07f blue:.07f alpha:1];
  72. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  73. UIViewController *rootViewController = [UIViewController new];
  74. rootViewController.view = rootView;
  75. self.window.rootViewController = rootViewController;
  76. [self.window makeKeyAndVisible];
  77. return YES;
  78. }
  79. // https://facebook.github.io/react-native/docs/linking.html
  80. - (BOOL)application:(UIApplication *)application
  81. openURL:(NSURL *)url
  82. sourceApplication:(NSString *)sourceApplication
  83. annotation:(id)annotation
  84. {
  85. return [RCTLinkingManager application:application
  86. openURL:url
  87. sourceApplication:sourceApplication
  88. annotation:annotation];
  89. }
  90. @end