如何在iOS远程通知上禁用默认通知警报视图? [英] How to disable default notification alert view on iOS remote notifications?

查看:49
本文介绍了如何在iOS远程通知上禁用默认通知警报视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我启用了远程通知,

In my app I enabled remote notifications,

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];
}

我实现了如下的委托方法,

And I implemented the delegate methods as follows,

- (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.我想

But when the app is in foreground and receiving a notification, I got a UIAlertView with the notification title and message. I want to

//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:上进行了调试,在触发之后,我得到了警报.我也通过删除此方法进行了测试.但是在收到通知时仍会显示此警报.

I debugged on willPresentNotification: and after this triggers I got the alert. And I tested by removing this method as well. But still this alert is showing when receiving a notification.

如何禁用此警报视图?我在iPhone上使用的是10.2 iOS

How may I disable this alert view? I'm using 10.2 iOS in my iPhone

推荐答案

我不认为 UIAlertController 来自通知.确定要在其他地方创建一个吗?

I don't think the UIAlertController comes from notifications. Are you sure you are not creating one elsewhere ?

您的通知的实现似乎还可以.

Your notifications' implementation seems ok.

您可以在项目中搜索并使用断点来查看是否有任何 UIAlertController 受到打击吗?

Can you search in your project and using breakpoints to see if any of your UIAlertControllers get hit?

这篇关于如何在iOS远程通知上禁用默认通知警报视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆