您知道从UIUserNotificationTypeNone传递到UIUserNotificationTypeAlert的方法吗? UIUserNotificationTypeBadge | UIUserNotificationTypeSound(iOS8)?
传递给UIUserNotificationTypeNone效果很好,但是当用户尝试再次切换以启用时效果不佳...
这是我的代码:
// Register for Push Notifications, if running iOS 8
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings * settingsAvailable = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settingsAvailable];
[application registerForRemoteNotifications];
}
else
{
// Register for Push Notifications before iOS 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
切换后启用委托的方法“didRegisterUserNotificationSettings”
// Register to receive notifications
[application registerForRemoteNotifications];
NSLog(@"The app is registered for the types: %@", notificationSettings);
返回:
The app is registered for the types: <UIUserNotificationSettings: 0x15e9e790; types: (none);>
提前致谢
最佳答案
这是因为通知设置已在系统设置中关闭。
关于ios - 从UIUserNotificationTypeNone传递给UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26261503/