【iOS】App处于前台时如何屏蔽系统通知
最新资讯 • U-Push运营助手
6222
2019-4-24
摘要:
【iOS】App处于前台时如何屏蔽系统通知

当应用处于前台时,本来是没有提醒的,SDK中为了更便于提醒用户,所以增加了前台时的弹窗通知。如果要关闭这个功能可以在以下两个地方设置。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { //关闭友盟自带的弹出框 [UMessage setAutoAlert:NO]; [UMessage didReceiveRemoteNotification:userInfo];}

//iOS10新增:处理前台收到通知的代理方法 -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{ NSDictionary * userInfo = notification.request.content.userInfo; if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { [UMessage setAutoAlert:NO]; //应用处于前台时的远程推送接受 //必须加这句代码 [UMessage didReceiveRemoteNotification:userInfo]; }else{ //应用处于前台时的本地推送接受 } completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert); }

如果要关闭系统的alert弹框,可以将上面的completionHandler的UNNotificationPresentationOptionAlert去掉。