iOS – 检查应用程序中的推送通知支持

我将推送通知添加到我的应用程序。 而我的应用程序基于推送通知。 当应用程序第一次运行时,它会显示警报用户是否想要接收推送通知。 是否可以强制接受推送通知? 或者,如果这是不可能的,我们可以检查是否为这个应用程序设置推送通知,并终止与警报的应用程序?

您只能检查用户是否select了接收推送通知:

UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; if (status == UIRemoteNotificationTypeNone) { NSLog(@"User doesn't want to receive push-notifications"); } 

//最好使用followi来代替

BOOL status = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; 如果(!status){NSLog(@“用户不想接收推送通知”); }

如果您的应用程序目标> = iOS 8.0 ,则可以使用:

 UIApplication.sharedApplication().isRegisteredForRemoteNotifications() 

因为enabledRemoteNotificationTypes已被弃用。