gpt4 book ai didi

ios - [[UIApplication sharedApplication] currentUserNotificationSettings].types 的调用总是返回 UIUserNotificationTypeNone

转载 作者:行者123 更新时间:2023-11-29 00:51:40 26 4
gpt4 key购买 nike

我需要检查用户是否在“设置”中启用了推送通知。为此,我使用此代码:

    if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications] == NO) {
NSLog(@"NO");
// NO
}
if ([[UIApplication sharedApplication]respondsToSelector:@selector(currentUserNotificationSettings)]){
UIUserNotificationSettings *noticationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!noticationSettings || (noticationSettings.types == UIUserNotificationTypeNone)) {
NSLog(@"NO");
// here it does not work, I enabled push notifications
// in settings and noticationSettings.types returns UIUserNotificationTypeNone
// NO
} else {
NSLog(@"YES");
// YES
}
}

但问题是 notificationSettings.types 总是返回 UIUserNotificationTypeNone,无论是否在“设置”中启用推送通知。

如图所示,我启用了推送通知,但 notificationSettings.types 返回了 UIUserNotificationTypeNone,有人能告诉我问题出在哪里吗?谢谢

enter image description here

最佳答案

您的屏幕截图表明您没有使用 UIUserNotificationTypeBadgeUIUserNotificationTypeSoundUIUserNotificationTypeAlert 调用 registerUserNotificationSettings

尝试以下操作:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge
|UIUserNotificationTypeSound
|UIUserNotificationTypeAlert) categories:nil];

UIApplication *application = [UIApplication sharedApplication];
[application registerUserNotificationSettings:settings];

关于ios - [[UIApplication sharedApplication] currentUserNotificationSettings].types 的调用总是返回 UIUserNotificationTypeNone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38078005/

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