iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了推送通知开启或关闭在iOS中检查大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
任何时候如果应用程序正在运行(或从恢复模式开启),我想在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)];
        }
    }

}

但是,现在我面临的问题是,只有在第一次发布应用程序之后才会出现。它像我想要的那样工作。但之后,如果我从“设置”关闭“推送通知”选项,则不会显示提示信息”。我该如何实现?如果有任何想法,请与我分享
– 先谢谢了。

解决方法

如果应用程序一旦注册了RegisterForRemoteNotification,那么您可以禁用以及启用。一旦您禁用,即将重新注册,那么这将启用registerForRemoteNotification,而不使用弹出窗口来进行警报。

Technical Note TN2265: Troubleshooting Push Notifications

更多信息:INFO && Info 2

编辑:用于检查与警报启用 –

使用

if (types & UIRemoteNotificationTypeAlert){}

代替

if (types == UIRemoteNotificationTypeNone){}

编辑:
doc for iOS 8 or later的最新更新,您可以查看:

- (BOOL)isRegisteredForRemoteNotifications

大佬总结

以上是大佬教程为你收集整理的推送通知开启或关闭在iOS中检查全部内容,希望文章能够帮你解决推送通知开启或关闭在iOS中检查所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: