AppDelegate.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. @interface AppDelegate()<PDRCoreDelegate>
  15. @property (strong, nonatomic) ViewController *h5ViewContoller;
  16. @end
  17. @implementation AppDelegate
  18. @synthesize window = _window;
  19. @synthesize rootViewController;
  20. #pragma mark -
  21. #pragma mark app lifecycle
  22. /*
  23. * @Summary:程序启动时收到push消息
  24. */
  25. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  26. {
  27. BOOL ret = [PDRCore initEngineWihtOptions:launchOptions
  28. withRunMode:PDRCoreRunModeNormal withDelegate:self];
  29. UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  30. self.window = window;
  31. ViewController *viewController = [[ViewController alloc] init];
  32. self.h5ViewContoller = viewController;
  33. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  34. self.rootViewController = navigationController;
  35. navigationController.navigationBarHidden = YES;
  36. {
  37. [self startMainApp];
  38. self.h5ViewContoller.showLoadingView = YES;
  39. }
  40. self.window.rootViewController = navigationController;
  41. [self.window makeKeyAndVisible];
  42. return ret;
  43. }
  44. -(BOOL)getStatusBarHidden {
  45. return [self.h5ViewContoller getStatusBarHidden];
  46. }
  47. -(UIStatusBarStyle)getStatusBarStyle {
  48. return [self.h5ViewContoller getStatusBarStyle];
  49. }
  50. -(void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle {
  51. [self.h5ViewContoller setStatusBarStyle:statusBarStyle];
  52. }
  53. -(void)wantsFullScreen:(BOOL)fullScreen
  54. {
  55. [self.h5ViewContoller wantsFullScreen:fullScreen];
  56. }
  57. #pragma mark -
  58. - (void)startMainApp {
  59. dispatch_async(dispatch_get_main_queue(), ^(void) {
  60. [[PDRCore Instance] start];
  61. });
  62. }
  63. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
  64. completionHandler:(void(^)(BOOL succeeded))completionHandler{
  65. [PDRCore handleSysEvent:PDRCoreSysEventPeekQuickAction withObject:shortcutItem];
  66. completionHandler(true);
  67. }
  68. - (void)applicationDidBecomeActive:(UIApplication *)application
  69. {
  70. [PDRCore handleSysEvent:PDRCoreSysEventBecomeActive withObject:nil];
  71. // 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.
  72. }
  73. - (void)applicationWillResignActive:(UIApplication *)application
  74. {
  75. [PDRCore handleSysEvent:PDRCoreSysEventResignActive withObject:nil];
  76. // 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.
  77. // 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.
  78. }
  79. - (void)applicationDidEnterBackground:(UIApplication *)application
  80. {
  81. [PDRCore handleSysEvent:PDRCoreSysEventEnterBackground withObject:nil];
  82. // 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.
  83. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  84. }
  85. - (void)applicationWillEnterForeground:(UIApplication *)application
  86. {
  87. [PDRCore handleSysEvent:PDRCoreSysEventEnterForeGround withObject:nil];
  88. // 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.
  89. }
  90. - (void)applicationWillTerminate:(UIApplication *)application
  91. {
  92. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  93. [PDRCore destoryEngine];
  94. }
  95. #pragma mark -
  96. #pragma mark URL
  97. - (BOOL)application:(UIApplication *)application
  98. openURL:(NSURL *)url
  99. sourceApplication:(NSString *)sourceApplication
  100. annotation:(id)annotation {
  101. [self application:application handleOpenURL:url];
  102. return YES;
  103. }
  104. /*
  105. * @Summary:程序被第三方调用,传入参数启动
  106. *
  107. */
  108. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  109. {
  110. [PDRCore handleSysEvent:PDRCoreSysEventOpenURL withObject:url];
  111. return YES;
  112. }
  113. - (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  114. [PDRCore handleSysEvent:PDRCoreSysEventOpenURLWithOptions withObject:@[url,options]];
  115. return YES;
  116. }
  117. /*
  118. * @Summary:远程push注册成功收到DeviceToken回调
  119. *
  120. */
  121. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  122. {
  123. NSLog(@"application--didRegisterForRemoteNotificationsWithDeviceToken[%@]", deviceToken);
  124. [PDRCore handleSysEvent:PDRCoreSysEventRevDeviceToken withObject:deviceToken];
  125. }
  126. /*
  127. * @Summary: 远程push注册失败
  128. */
  129. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  130. {
  131. [PDRCore handleSysEvent:PDRCoreSysEventRegRemoteNotificationsError withObject:error];
  132. }
  133. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  134. [PDRCore handleSysEvent:PDRCoreSysEventRevRemoteNotification withObject:userInfo];
  135. }
  136. - (void)application:(UIApplication *)application
  137. didReceiveRemoteNotification:(NSDictionary *)userInfo
  138. fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
  139. [self application:application didReceiveRemoteNotification:userInfo];
  140. completionHandler(UIBackgroundFetchResultNewData);
  141. }
  142. /*
  143. * @Summary:程序收到本地消息
  144. */
  145. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
  146. {
  147. [PDRCore handleSysEvent:PDRCoreSysEventRevLocalNotification withObject:notification];
  148. }
  149. @end
  150. @implementation UINavigationController(Orient)
  151. -(BOOL)shouldAutorotate{
  152. return ![PDRCore Instance].lockScreen;
  153. return YES;
  154. }
  155. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
  156. if([self.topViewController isKindOfClass:[ViewController class]])
  157. return [self.topViewController supportedInterfaceOrientations];
  158. return UIInterfaceOrientationMaskPortrait;
  159. }
  160. @end