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

Sat*_*yam 11 push-notification ios

我在我的应用程序中添加了Push通知.我的应用程序基于推送通知.当应用程序第一次运行时,它会显示用户是否想要接收推送通知的警报.是否可以强制接受推送通知?或者,如果无法做到这一点,我们是否可以检查是否为此应用设置了推送通知,并通过警报终止应用程序?

Nek*_*kto 22

您只能检查用户是否已选择接收推送通知:

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

  • 现在已弃用.在iOS8之后应该使用isRegisteredForRemoteNotifications. (4认同)