gpt4 book ai didi

iOS7 - enabledRemoteNotificationTypes 返回 UIRemoteNotificationTypeNone 但在 Settings.app Alert、Badge 和 Sound 中启用

转载 作者:可可西里 更新时间:2023-11-01 03:18:26 24 4
gpt4 key购买 nike

我在 View Controller 按钮操作中有以下代码:

- (IBAction)requestPermissions:(id)sender
{
DDLogInfo(@"Start permission requesting.");

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]){
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
}
}

注册完成后 didBecomeActive 通知被发布,我正在检查用户做了什么:

-(void)didBecomeActive:(NSNotification *)notification
{
if([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone){
// if user decline
}
} else {
// if user accept
}

所以我的问题是:如果用户拒绝接收推送通知并稍后决定启用它们(设置->通知中心->我的应用程序),会有一个惊喜: 'Alert' , 'Badge' 和 'Sound' 是在“设置”中启用,但应用返回 UIRemoteNotificationTypeNone

知道哪里出了问题吗?

注意:我知道这些方法已被弃用,所以请不要告诉我使用 registerForRemoteNotifications:UIUserNotificationSettings,它已经完成了。

最佳答案

好吧,它可能会在应用重启后返回一个正确的值,你能检查一下吗?我发现当您的应用程序在后台时更改设置中的权限时 iOS 会自动终止您的应用程序的情况,例如。照片提要访问;我想在这种情况下这只是 iOS 中的错误实现,这不会让我感到惊讶。我想我也遇到过你描述的这种情况,在发现它返回无效/旧值直到重新启动后,我放弃并在需要重新启动时进行流量计数。

无论如何,我认为您对此无能为力。

关于iOS7 - enabledRemoteNotificationTypes 返回 UIRemoteNotificationTypeNone 但在 Settings.app Alert、Badge 和 Sound 中启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34856123/

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