gpt4 book ai didi

ios - 如何禁用 iOS 远程通知的默认通知警报 View ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:33:59 26 4
gpt4 key购买 nike

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

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

我按如下方式实现了委托(delegate)方法,

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

如何禁用此警报 View ?我在我的 iPhone 中使用 10.2 iOS

enter image description here

最佳答案

我不认为 UIAlertController 来自通知。您确定您没有在别处创建一个吗?

您的通知实现似乎没问题。

您能否在您的项目中搜索并使用断点来查看是否有任何 UIAlertController 被命中?

关于ios - 如何禁用 iOS 远程通知的默认通知警报 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42384753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com