Keine Beschreibung

AppDelegate.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // AppDelegate.m
  3. // ACSION
  4. //
  5. // Created by sunyue on 2019/4/22.
  6. // Copyright © 2019 acsion. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "ASTabViewController.h"
  10. #import "MiPushSDK.h"
  11. @interface AppDelegate () <MiPushSDKDelegate,UNUserNotificationCenterDelegate>
  12. @end
  13. @implementation AppDelegate
  14. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  15. // Override point for customization after application launch.
  16. [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
  17. [[UINavigationBar appearance] setTintColor:[UIColor baseColor]];
  18. [[UINavigationBar appearance] setBarTintColor:[UIColor baseColor]];
  19. [self regMI:launchOptions];
  20. [self regUM];
  21. [self regRootController];
  22. return YES;
  23. }
  24. - (void)regMI:(NSDictionary *)launchOptions {
  25. if (@available(iOS 10.0, *)) {
  26. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  27. [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
  28. if (granted) {
  29. [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  30. }];
  31. }
  32. }];
  33. center.delegate = self;
  34. [MiPushSDK registerMiPush:self type:0 connect:YES];
  35. } else {
  36. [MiPushSDK registerMiPush:self type:0 connect:YES];
  37. }
  38. NSDictionary *dic = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
  39. if (dic) {
  40. NSString *idStr = [dic objectForKey:@"_id_"];
  41. if (idStr) {
  42. [MiPushSDK openAppNotify:idStr];
  43. }
  44. }
  45. }
  46. - (void)regUM {
  47. UMConfigInstance.appKey = UMAPP_KEY;
  48. UMConfigInstance.channelId = @"App Store";
  49. [MobClick startWithConfigure:UMConfigInstance];
  50. }
  51. - (void)regRootController {
  52. _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  53. ASTabViewController *vc = [[ASTabViewController alloc] init];
  54. _window.rootViewController = vc;
  55. [_window makeKeyAndVisible];
  56. }
  57. - (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data {
  58. }
  59. - (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data {
  60. }
  61. - (void)miPushReceiveNotification:(NSDictionary *)data {
  62. }
  63. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  64. [MiPushSDK handleReceiveRemoteNotification:userInfo];
  65. }
  66. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
  67. NSDictionary *dic = notification.request.content.userInfo;
  68. if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  69. [MiPushSDK handleReceiveRemoteNotification:dic];
  70. }
  71. completionHandler(UNNotificationPresentationOptionAlert);
  72. }
  73. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
  74. NSDictionary *dic = response.notification.request.content.userInfo;
  75. if ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  76. [MiPushSDK handleReceiveRemoteNotification:dic];
  77. }
  78. completionHandler();
  79. }
  80. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  81. [MiPushSDK bindDeviceToken:deviceToken];
  82. }
  83. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  84. }
  85. - (void)applicationWillResignActive:(UIApplication *)application {
  86. // 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.
  87. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  88. }
  89. - (void)applicationDidEnterBackground:(UIApplication *)application {
  90. // 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.
  91. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  92. }
  93. - (void)applicationWillEnterForeground:(UIApplication *)application {
  94. // 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.
  95. }
  96. - (void)applicationDidBecomeActive:(UIApplication *)application {
  97. // 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.
  98. }
  99. - (void)applicationWillTerminate:(UIApplication *)application {
  100. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  101. }
  102. @end