【发布时间】:2013-12-20 21:44:53
【问题描述】:
如果应用程序正在运行(或从恢复模式打开),我想随时检查 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];
}
}
然后我使用以下代码转到“设置选项卡>>通知中心”,以便用户可以手动打开它:
- (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)];
}
}
}
但是,现在我面临的问题是,它只在启动应用程序后第一次出现。它按我的意愿工作。但在那之后,如果我从“设置”中关闭“推送通知选项”,它不会给我任何“警报消息”。
【问题讨论】:
标签: ios iphone ipad push-notification apple-push-notifications