我应该检查通知中心的应用程序的禁用设置是否为假?
-(BOOL)pushEnabled
{
BOOL enabled = NO;
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
enabled = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
}
else
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
enabled = types & UIRemoteNotificationTypeAlert;
}
return enabled; }
答案 0 :(得分:2)
isRegisteredForRemoteNotificaitons
的苹果文档说回报是:
如果应用程序已注册远程通知并收到其设备令牌,则为YES;如果未发生注册,失败或用户已拒绝,则为“否”。
因此,如果您成功注册了远程通知,那么无论系统设置如何,isRegisteredForRemoteNotifications
都将返回YES
。
如果您想查看UIUserNotificationSettings
,那么这应该有效:
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
// not enabled
} else {
// enabled
}
如果您正在使用< iOS 8然后这应该工作:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){
UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!notificationSettings || (notificationSettings.types == UIUserNotificationTypeNone)) {
// not enabled
} else {
// enabled
}
} else {
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types) {
// enabled
} else {
// not enabled
}
}
}