AppDelegate.m 6.8 KB

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