从UIUserNotificationTypeNone传递到UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound
您知道从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:
提前致谢
这是因为系统设置中的通知设置已关闭。