// // AppDelegate+SPSBPushNotification.m // 我的社保 // // Created by shanp on 2021/4/26. // #import "AppDelegate+SPSBPushNotification.h" #import #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 #import #endif #import "SPSBCustomerServiceManager.h" #import "SPSBGeneralManager.h" #import "SPSBConsultationViewController.h" #import "SPSBBusinessManager.h" #import #import #import "SPSBKeyProfile.h" @interface AppDelegate () @end @implementation AppDelegate (SPSBPushNotification) - (void)handlePushWithOptions:(NSDictionary *)launchOptions { if (@available(iOS 10.0, *)) { [UNUserNotificationCenter currentNotificationCenter].delegate = self; } [UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:nil completionHandler:^(BOOL granted, NSError * _Nullable error) { if (granted) { //点击允许 } else { //点击不允许 } }]; #ifdef DEBUG [UMessage openDebugMode:true]; #endif if (launchOptions && launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) { UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]; if (notification.userInfo[@"pushType"] && [notification.userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) { spsb_customerServiceManager().spsb_isClickNotification = true; } } else if (launchOptions && launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) { NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo[@"pushType"] && [userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) { spsb_customerServiceManager().spsb_isClickNotification = true; } } } - (void)registerAccount { [UMessage setAlias:[jxh_userDefaults() objectForKey:SPSBUser] type:@"WODESHEBAO_UID" response:^(id _Nullable responseObject, NSError * _Nullable error) { debugLog(@"-----000000-------%@", responseObject); }]; } - (void)checkCustomerService { if (!spsb_customerServiceManager().spsb_isChecking) { [spsb_customerServiceManager() checkSobot]; } else if (!spsb_customerServiceManager().spsb_isIn) { spsb_customerServiceManager().spsb_notificationNum ++; [spsb_consultationHomeVC() reloadViewTips]; } } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { //关闭友盟自带的弹出框 [UMessage setAutoAlert:false]; [UMessage didReceiveRemoteNotification:userInfo]; if (userInfo[@"pushType"] && [userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) { [self checkCustomerService]; } } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { debugLog(@"%@", application); debugLog(@"%@", notification); debugLog(@"%@", notification.userInfo); debugLog(@"%@", notification.alertBody); debugLog(@"%ld", (long)spsb_isAppActive()); if (!spsb_isAppActive()) { spsb_customerServiceManager().spsb_isClickNotification = true; [spsb_customerServiceManager() toOnlineContactWithBaseController:nil]; return; } [[UIApplication sharedApplication] cancelLocalNotification:notification]; if (notification.userInfo[@"pushType"] && [notification.userInfo[@"pushType"] hasPrefix:@"www.sobot.com"]) { [self checkCustomerService]; } } //iOS10新增:处理前台收到通知的代理方法 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){ NSDictionary * userInfo = notification.request.content.userInfo; debugLog(@"notification---%@", userInfo); if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [UMessage setAutoAlert:false]; //应用处于前台时的远程推送接受 //必须加这句代码 [UMessage didReceiveRemoteNotification:userInfo]; [UMessage sendClickReportForRemoteNotification:userInfo]; } else { //应用处于前台时的本地推送接受 } if (notification.request.identifier && [notification.request.identifier hasPrefix:@"www.sobot.com"]) { [self checkCustomerService]; } completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert); } //iOS10新增:处理后台点击通知的代理方法 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){ NSDictionary * userInfo = response.notification.request.content.userInfo; if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { //应用处于后台时的远程推送接受 //必须加这句代码 [UMessage didReceiveRemoteNotification:userInfo]; } else { //应用处于后台时的本地推送接受 } if (response.notification.request.identifier && [response.notification.request.identifier hasPrefix:@"www.sobot.com"]) { spsb_customerServiceManager().spsb_isClickNotification = true; [spsb_customerServiceManager() toOnlineContactWithBaseController:nil]; } } @end