我正在使用推送通知开发应用程序.要检查所有可能的用户交互方式,我想在用户拒绝在第一次启动时为我的应用启用推送通知时测试我的应用.
registerForRemoteNotificationTypes但是,对话框(由其启动)仅在每个应用程序中出现一次.如何重置iPhone OS的应用程序内存.删除应用程序并重新安装没有帮助.
如果应用程序正在运行(或从恢复模式打开),我想在iOS设备中检查"推送通知选项".如果选项为OFF,我使用以下代码进行检查:
-(void)PushNotificationServiceChecking
{
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
{
NSString *msg = @"Please press ON to enable Push Notification";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ON", nil];
alert.tag = 2;
[alert show];
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用以下代码进入"设置选项卡>>通知中心",以便用户可以手动操作:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 2)
{
if (buttonIndex == 0)
{
// this is the cancel button
}
else if (buttonIndex == 1)
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];
}
}
} …Run Code Online (Sandbox Code Playgroud)