酷店

AppDelegate.m 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // AppDelegate.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "KDPTabBarVC.h"
  10. #import "KDPAccountTool.h"
  11. #import "KDPWelcomePageViewController.h"
  12. #import "KDPNoticeViewController.h"
  13. @interface AppDelegate ()
  14. @end
  15. @implementation AppDelegate
  16. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  17. [self setUpKeyWindow];
  18. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  19. [self setUpUM];
  20. [self setUpMiPush];
  21. return YES;
  22. }
  23. - (void)setUpKeyWindow{
  24. self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  25. self.window.backgroundColor=[UIColor whiteColor];
  26. self.window.rootViewController=[[KDPTabBarVC alloc]init];
  27. [self.window makeKeyAndVisible];
  28. KDPAccountModel *accountModel = [KDPAccountTool account];
  29. if (![KDPAccountTool isLogin] || [accountModel.has_kwai integerValue] != 1) {
  30. [self.window.rootViewController presentViewController:[[UINavigationController alloc]initWithRootViewController:[[KDPWelcomePageViewController alloc]init]] animated:YES completion:nil];
  31. }
  32. }
  33. #pragma mark - 推送
  34. - (void)setUpMiPush{
  35. [MiPushSDK registerMiPush:self];
  36. }
  37. #pragma mark--友盟统计
  38. -(void)setUpUM
  39. {
  40. UMConfigInstance.appKey=UMENG_KEY;
  41. UMConfigInstance.channelId=@"App Store";
  42. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  43. NSString *appVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  44. [MobClick setAppVersion:appVersion];
  45. [MobClick startWithConfigure:UMConfigInstance];
  46. [MobClick setLogEnabled:YES];
  47. }
  48. #pragma mark 注册push服务.
  49. - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  50. {
  51. NSLog(@"APNS token: %@", [deviceToken description]);
  52. // 注册APNS成功, 注册deviceToken
  53. [MiPushSDK bindDeviceToken:deviceToken];
  54. }
  55. - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
  56. {
  57. NSLog(@"APNS error: %@", err);
  58. // 注册APNS失败.
  59. // 自行处理.
  60. }
  61. #pragma mark MiPushSDKDelegate
  62. - (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data
  63. {
  64. // 请求成功
  65. // 可在此获取regId
  66. if ([selector isEqualToString:@"bindDeviceToken:"]) {
  67. NSLog(@"regid = %@", data[@"regid"]);
  68. }
  69. }
  70. - (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data
  71. {
  72. // 请求失败
  73. }
  74. #pragma mark Local And Push Notification
  75. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  76. {
  77. NSLog(@"APNS notify: %@", userInfo);
  78. // 当同时启动APNs与内部长连接时, 把两处收到的消息合并. 通过miPushReceiveNotification返回
  79. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  80. }
  81. // iOS10新加入的回调方法
  82. // 应用在前台收到通知
  83. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0) {
  84. NSDictionary * userInfo = notification.request.content.userInfo;
  85. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  86. NSLog(@"APNS notify: %@", userInfo);;
  87. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  88. NSString *messageId = [userInfo objectForKey:@"_id_"];
  89. [MiPushSDK openAppNotify:messageId];
  90. }
  91. [self cancelIconBadgeNumber];
  92. }
  93. - (void)cancelIconBadgeNumber {
  94. // 注册显示应用程序BadgeNumber的通知
  95. UIApplication *application = [UIApplication sharedApplication];
  96. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
  97. [application registerUserNotificationSettings:settings];
  98. if (application.applicationIconBadgeNumber > 0) {
  99. application.applicationIconBadgeNumber = 0;
  100. }
  101. }
  102. // 点击通知进入应用
  103. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler __IOS_AVAILABLE(10.0) {
  104. NSDictionary * userInfo = response.notification.request.content.userInfo;
  105. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  106. NSLog(@"APNS notify: %@", userInfo);
  107. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  108. NSString *messageId = [userInfo objectForKey:@"_id_"];
  109. [MiPushSDK openAppNotify:messageId];
  110. }
  111. [self jumpViewController:userInfo];
  112. completionHandler();
  113. }
  114. - (void)jumpViewController:(NSDictionary *)remoteNotification {
  115. [self cancelIconBadgeNumber];
  116. NSInteger pushType = [remoteNotification[@"pushType"] integerValue];
  117. switch (pushType) {
  118. case 1005://跳转到消息列表
  119. [self pushMessage];
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. #pragma mark---消息列表
  126. -(void)pushMessage
  127. {
  128. KDPNoticeViewController *message=[[KDPNoticeViewController alloc]init];
  129. [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:[[UINavigationController alloc]initWithRootViewController:message] animated:YES completion:nil];
  130. }
  131. - (void)applicationWillResignActive:(UIApplication *)application {
  132. // 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.
  133. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  134. }
  135. - (void)applicationDidEnterBackground:(UIApplication *)application {
  136. // 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.
  137. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  138. }
  139. - (void)applicationWillEnterForeground:(UIApplication *)application {
  140. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  141. }
  142. - (void)applicationDidBecomeActive:(UIApplication *)application {
  143. // 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.
  144. }
  145. - (void)applicationWillTerminate:(UIApplication *)application {
  146. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  147. }
  148. @end