如何显示iOS推送通知弹出窗口?

ces*_*eet 15 notifications push-notification apple-push-notifications ios

我正在尝试向我的应用添加推送通知.我需要知道如何显示推送通知弹出窗口.我所关注的弹出窗口是一个警报视图,有两个选项,"允许"和"不允许".它询问用户是否允许应用程序接收通知和内容.

我已经尝试一遍又一遍地删除我的应用程序并推进时间但没有任何效果.

此外,如果出现弹出窗口,我如何知道所选用户是否不允许/允许?

Era*_*ran 45

重置iOS上的推送通知权限警报

第一次启用推送的应用程序注册推送通知时,iOS会询问用户是否希望接收该应用程序的通知.一旦用户响应此警报,除非设备已恢复或应用程序已卸载至少一天,否则不会再次显示该警报.

如果您想模拟首次运行的应用,可以将应用程序卸载一天.您可以通过以下步骤实现后者而无需等待一天:

1. Delete your app from the device.

2. Turn the device off completely and turn it back on.

3. Go to Settings > General > Date & Time and set the date ahead a day or more.

4. Turn the device off completely again and turn it back on.
Run Code Online (Sandbox Code Playgroud)

资源


Svi*_*miv 11

在您注册远程通知申请后,弹出窗口即显示.例如:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Run Code Online (Sandbox Code Playgroud)

我怎么知道用户选择不允许/允许?

应用程序对象调用两个委托的方法:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{

}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error
{
}
Run Code Online (Sandbox Code Playgroud)

UPD: 这是关于如何为推送通知设置应用程序的教程:http://www.raywenderlich.com/32960/