如何禁用iOS远程通知的默认通知警报视图?
在我的应用中,我启用了远程通知,
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")){ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if( !error ){ [[UIApplication sharedApplication] registerForRemoteNotifications]; } }]; }else{ UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound); UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; }
我实现了如下的委托方法,
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ NSLog(@"Failed!!"); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { // Print message. if (userInfo) { NSLog(@"Message ID: %@", userInfo); } completionHandler(UIBackgroundFetchResultNoData); }
但是,当应用程序在前台并收到通知时,我得到了一个带有通知标题和消息的UIAlertView。 我要
//Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ NSLog(@"User Info : %@",notification.request.content.userInfo); completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionBadge); } //Called to let your app know which action was selected by the user for a given notification. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ NSLog(@"User Info : %@",response.notification.request.content.userInfo); completionHandler(); }
我在willPresentNotification:
debuggingwillPresentNotification:
在触发后,我得到了警报。 我也通过删除这个方法来testing。 但收到通知时仍显示此警报。
如何禁用此警报视图? 我在iPhone中使用了10.2 iOS
我不认为UIAlertController
来自通知。 你确定你没有在别处创build一个吗?
您的通知的实施似乎没问题。
你可以在你的项目中search并使用断点来查看你的UIAlertController
受到攻击?