推送通知不会立即更新
Posted
技术标签:
【中文标题】推送通知不会立即更新【英文标题】:Push notification doesn't update immediately 【发布时间】:2015-02-26 09:43:06 【问题描述】:我正在使用 ios 8+ 上的推送通知。我尝试更新 UIUserNotificationSettings 值并将其取回进行比较,但它不一样。有人可以帮我解决/解释这个问题吗?非常感谢。
这是我的代码:
UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
NSLog(@"Before register: %u", types);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
UIUserNotificationSettings* currentSeting = [[UIApplication sharedApplication] currentUserNotificationSettings];
NSLog(@"After register: %u", currentSeting.types);
这里是输出控制台:
Before register: 6
After register: 0
【问题讨论】:
【参考方案1】:尝试在didRegisterUserNotificationSettings
委托方法中检查它,如下所示:
-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings
UIUserNotificationSettings* currentSeting = [[UIApplication sharedApplication] currentUserNotificationSettings];
【讨论】:
currentSeting 还是 0 确保在您的设备设置中为您的应用开启推送通知以防万一。 这里是官方文档developer.apple.com/library/prerelease/ios/documentation/UIKit/…以上是关于推送通知不会立即更新的主要内容,如果未能解决你的问题,请参考以下文章