如何在iOS远程通知上禁用默认通知警报视图?
在我的应用程序中,我启用了远程通知如何在iOS远程通知上禁用默认通知警报视图?,ios,objective-c,iphone,notifications,Ios,Objective C,Iphone,Notifications,在我的应用程序中,我启用了远程通知 if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")){ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizat
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:
上进行了调试,触发后我收到了警报。我也通过移除这个方法进行了测试。但在收到通知时仍会显示此警报
如何禁用此警报视图?我在iPhone中使用10.2 iOS
我不认为
UIAlertController
来自通知。你确定你没有在其他地方创建吗
您的通知的实现似乎还可以
能否在项目中搜索并使用断点查看是否有任何
UIAlertController
s被命中?在completionHandler中使用UNNotificationPresentationOptionNone
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(@"User Info : %@",notification.request.content.userInfo);
completionHandler(UNNotificationPresentationOptionNone);
}
你说的禁用是什么意思?根本看不到警报?!你的意思是把它转换成无声的推动?是的。看不到警报。“你是说将其转换为无声推送?”是的。我不需要显示警觉,这很奇怪。好吧,当你在前景中时,你不应该看到警报。我不知道为什么会这样。你能不能用CMD+Shift+F(全球项目研究)来获取关于这个AlertView的每一条线索。例如,您可以搜索“initWithTitle:“Alert”或“message:“Alert”。为了找到这个AlertView,我做了。但是没有像这样的警报。你尝试过所有的警报控制器吗?我对他的答案作了修改。他以前在AlertView中使用过…@亲爱的,谢谢,这是个错误。