AppDelegate+SPSBPushNotification.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // AppDelegate+SPSBPushNotification.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/26.
  6. //
  7. #import "AppDelegate+SPSBPushNotification.h"
  8. #import <UMPush/UMessage.h>
  9. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
  10. #import <UserNotifications/UserNotifications.h>
  11. #endif
  12. #import "SPSBCustomerServiceManager.h"
  13. #import "SPSBGeneralManager.h"
  14. #import "SPSBConsultationViewController.h"
  15. #import "SPSBBusinessManager.h"
  16. #import <JXHMacro.h>
  17. #import <JXHSystemShortcut.h>
  18. #import "SPSBKeyProfile.h"
  19. @interface AppDelegate ()<UNUserNotificationCenterDelegate>
  20. @end
  21. @implementation AppDelegate (SPSBPushNotification)
  22. - (void)handlePushWithOptions:(NSDictionary *)launchOptions {
  23. if (@available(iOS 10.0, *)) {
  24. [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  25. }
  26. [UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:nil completionHandler:^(BOOL granted, NSError * _Nullable error) {
  27. if (granted) {
  28. //点击允许
  29. } else {
  30. //点击不允许
  31. }
  32. }];
  33. #ifdef DEBUG
  34. [UMessage openDebugMode:true];
  35. #endif
  36. if (launchOptions && launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) {
  37. UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
  38. if (notification.userInfo[@"pushType"] && [notification.userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) {
  39. spsb_customerServiceManager().spsb_isClickNotification = true;
  40. }
  41. } else if (launchOptions && launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
  42. NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
  43. if (userInfo[@"pushType"] && [userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) {
  44. spsb_customerServiceManager().spsb_isClickNotification = true;
  45. }
  46. }
  47. }
  48. - (void)registerAccount {
  49. [UMessage setAlias:[jxh_userDefaults() objectForKey:SPSBUser] type:@"WODESHEBAO_UID" response:^(id _Nullable responseObject, NSError * _Nullable error) {
  50. debugLog(@"-----000000-------%@", responseObject);
  51. }];
  52. }
  53. - (void)checkCustomerService {
  54. if (!spsb_customerServiceManager().spsb_isChecking) {
  55. [spsb_customerServiceManager() checkSobot];
  56. } else if (!spsb_customerServiceManager().spsb_isIn) {
  57. spsb_customerServiceManager().spsb_notificationNum ++;
  58. [spsb_consultationHomeVC() reloadViewTips];
  59. }
  60. }
  61. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  62. //关闭友盟自带的弹出框
  63. [UMessage setAutoAlert:false];
  64. [UMessage didReceiveRemoteNotification:userInfo];
  65. if (userInfo[@"pushType"] && [userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) {
  66. [self checkCustomerService];
  67. }
  68. }
  69. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  70. debugLog(@"%@", application);
  71. debugLog(@"%@", notification);
  72. debugLog(@"%@", notification.userInfo);
  73. debugLog(@"%@", notification.alertBody);
  74. debugLog(@"%ld", (long)spsb_isAppActive());
  75. if (!spsb_isAppActive()) {
  76. spsb_customerServiceManager().spsb_isClickNotification = true;
  77. [spsb_customerServiceManager() toOnlineContactWithBaseController:nil];
  78. return;
  79. }
  80. [[UIApplication sharedApplication] cancelLocalNotification:notification];
  81. if (notification.userInfo[@"pushType"] && [notification.userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) {
  82. [self checkCustomerService];
  83. }
  84. }
  85. //iOS10新增:处理前台收到通知的代理方法
  86. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
  87. NSDictionary * userInfo = notification.request.content.userInfo;
  88. debugLog(@"notification---%@", userInfo);
  89. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  90. [UMessage setAutoAlert:false];
  91. //应用处于前台时的远程推送接受
  92. //必须加这句代码
  93. [UMessage didReceiveRemoteNotification:userInfo];
  94. [UMessage sendClickReportForRemoteNotification:userInfo];
  95. } else {
  96. //应用处于前台时的本地推送接受
  97. }
  98. if (notification.request.identifier && [notification.request.identifier hasPrefix:@"www.sobot.com"]) {
  99. [self checkCustomerService];
  100. }
  101. completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
  102. }
  103. //iOS10新增:处理后台点击通知的代理方法
  104. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
  105. NSDictionary * userInfo = response.notification.request.content.userInfo;
  106. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  107. //应用处于后台时的远程推送接受
  108. //必须加这句代码
  109. [UMessage didReceiveRemoteNotification:userInfo];
  110. } else {
  111. //应用处于后台时的本地推送接受
  112. }
  113. if (response.notification.request.identifier && [response.notification.request.identifier hasPrefix:@"www.sobot.com"]) {
  114. spsb_customerServiceManager().spsb_isClickNotification = true;
  115. [spsb_customerServiceManager() toOnlineContactWithBaseController:nil];
  116. }
  117. }
  118. @end