AppDelegate.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // AppDelegate.m
  3. // Pandora
  4. //
  5. // Created by Mac Pro_C on 12-12-26.
  6. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "PDRCore.h"
  10. #import "PDRCommonString.h"
  11. #import "ViewController.h"
  12. #import "PDRCoreApp.h"
  13. #import "PDRCoreAppManager.h"
  14. #define ENABLEAD
  15. @interface AppDelegate()<PDRCoreDelegate>
  16. @property (strong, nonatomic) ViewController *h5ViewContoller;
  17. @end
  18. @implementation AppDelegate
  19. @synthesize window = _window;
  20. @synthesize rootViewController;
  21. #pragma mark -
  22. #pragma mark app lifecycle
  23. /*
  24. * @Summary:程序启动时收到push消息
  25. */
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  27. {
  28. BOOL ret = [PDRCore initEngineWihtOptions:launchOptions
  29. withRunMode:PDRCoreRunModeNormal withDelegate:self];
  30. UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  31. self.window = window;
  32. ViewController *viewController = [[ViewController alloc] init];
  33. self.h5ViewContoller = viewController;
  34. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  35. self.rootViewController = navigationController;
  36. navigationController.navigationBarHidden = YES;
  37. {
  38. [self startMainApp];
  39. self.h5ViewContoller.showLoadingView = YES;
  40. }
  41. self.window.rootViewController = navigationController;
  42. [self.window makeKeyAndVisible];
  43. return ret;
  44. }
  45. -(BOOL)getStatusBarHidden {
  46. return [self.h5ViewContoller getStatusBarHidden];
  47. }
  48. -(UIStatusBarStyle)getStatusBarStyle {
  49. return [self.h5ViewContoller getStatusBarStyle];
  50. }
  51. -(void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle {
  52. [self.h5ViewContoller setStatusBarStyle:statusBarStyle];
  53. }
  54. -(void)wantsFullScreen:(BOOL)fullScreen
  55. {
  56. [self.h5ViewContoller wantsFullScreen:fullScreen];
  57. }
  58. #pragma mark -
  59. - (void)startMainApp {
  60. dispatch_async(dispatch_get_main_queue(), ^(void) {
  61. [[PDRCore Instance] start];
  62. });
  63. }
  64. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
  65. completionHandler:(void(^)(BOOL succeeded))completionHandler{
  66. [PDRCore handleSysEvent:PDRCoreSysEventPeekQuickAction withObject:shortcutItem];
  67. completionHandler(true);
  68. }
  69. - (void)applicationDidBecomeActive:(UIApplication *)application
  70. {
  71. [PDRCore handleSysEvent:PDRCoreSysEventBecomeActive withObject:nil];
  72. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  73. }
  74. - (void)applicationWillResignActive:(UIApplication *)application
  75. {
  76. [PDRCore handleSysEvent:PDRCoreSysEventResignActive withObject:nil];
  77. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  78. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  79. }
  80. - (void)applicationDidEnterBackground:(UIApplication *)application
  81. {
  82. [PDRCore handleSysEvent:PDRCoreSysEventEnterBackground withObject:nil];
  83. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  84. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  85. }
  86. - (void)applicationWillEnterForeground:(UIApplication *)application
  87. {
  88. [PDRCore handleSysEvent:PDRCoreSysEventEnterForeGround withObject:nil];
  89. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  90. }
  91. - (void)applicationWillTerminate:(UIApplication *)application
  92. {
  93. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  94. [PDRCore destoryEngine];
  95. }
  96. #pragma mark -
  97. #pragma mark URL
  98. - (BOOL)application:(UIApplication *)application
  99. openURL:(NSURL *)url
  100. sourceApplication:(NSString *)sourceApplication
  101. annotation:(id)annotation {
  102. [self application:application handleOpenURL:url];
  103. return YES;
  104. }
  105. /*
  106. * @Summary:程序被第三方调用,传入参数启动
  107. *
  108. */
  109. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  110. {
  111. [PDRCore handleSysEvent:PDRCoreSysEventOpenURL withObject:url];
  112. return YES;
  113. }
  114. - (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  115. [PDRCore handleSysEvent:PDRCoreSysEventOpenURLWithOptions withObject:@[url,options]];
  116. return YES;
  117. }
  118. /*
  119. * @Summary:通用链接
  120. */
  121. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler {
  122. [PDRCore handleSysEvent:PDRCoreSysEventContinueUserActivity withObject:userActivity];
  123. restorationHandler(nil);
  124. return YES;
  125. }
  126. @end
  127. @implementation UINavigationController(Orient)
  128. -(BOOL)shouldAutorotate{
  129. return ![PDRCore Instance].lockScreen;
  130. return YES;
  131. }
  132. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
  133. if([self.topViewController isKindOfClass:[ViewController class]])
  134. return [self.topViewController supportedInterfaceOrientations];
  135. return UIInterfaceOrientationMaskPortrait;
  136. }
  137. @end