gpt4 book ai didi

ios - 我如何确定用户是否曾经看到过请求推送通知权限的对话框 (ios)

转载 作者:可可西里 更新时间:2023-11-01 04:04:13 25 4
gpt4 key购买 nike

我知道 enabledremotenotificationtypes,但它对我没有帮助,因为如果我收到 enabledremotenotificationtypes == UIRemoteNotificationTypeNone,我无法判断用户是否有 1. 接受过一次推送通知但随后通过稍后设置将其关闭或2. 拒绝推送通知或 3. 从未见过请求许可的蓝色对话框。我需要一种方法来区分这三种情况。

任何帮助将不胜感激。

最佳答案

该解决方案有点麻烦,但确实有效。您需要为两种不同的 notificationSettings 调用 registerUserNotificationSettings - 一种没有 notificationCategory,一种带有 notificationCategory:

    //Request notification permission
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

//Request notification permission again, but with a category with no actions
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init];
category.identifier = @"com.xyz.markNotificationPopupShownCategoryIdentifier";

UIUserNotificationSettings *notificationSettingsWithCategory = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:[NSSet setWithObject:category]];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettingsWithCategory];

app delegate中的didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings方法会被调用两次,无论用户在权限通知中的回答如何,第二次调用后,当前的通知设置都会包含该类别。只要类别计数大于 0,就可以确定通知权限对话框已经显示:

if ([UIApplication sharedApplication].currentUserNotificationSettings.categories.count > 0) {
NSLog(@"Notifications permissions has been asked");
} else {
NSLog(@"Notifications permissions hasn't been asked");
}

关于ios - 我如何确定用户是否曾经看到过请求推送通知权限的对话框 (ios),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12336466/

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