无需注册即可显示推送通知弹出窗口?

时间:2016-07-27 12:35:14

标签: ios objective-c push-notification

我正在尝试显示AlertView,要求用户仅在用户点击按钮时才允许推送通知。

我在按钮的操作中注册了推送通知:

[[UIApplication sharedApplication] registerForRemoteNotifications];

显然,与推送通知相关的Delegate方法是在appDelegate中实现的。

问题是,尽管我没有在我的appDelegate中注册,但在启动应用程序时允许推送通知的警告。

事实上,据我所知,只有在我拨打registerForRemoteNotifications时才会显示alertView。

我错过了什么?

1 个答案:

答案 0 :(得分:0)

首先,您需要使用此代码注册UIUserNotificationSettings

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

当上面的代码调用时,这个委托方法将调用。

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [application registerForRemoteNotifications];
}