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

AppDelegate.m 3.7KB

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