关于重置IOS App请求推送的授权请求

项目要添加推送通知,测试完本地通知后,发现测不了远程通知。于是想重置授权请求。

以下是重置授权请求的方法:

方法一:

通用->还原->抹掉所有内容和设置

但是第一种方法很费时,抹掉内容估计得几十分钟。于是有了第二种方法。


方法二:

将App从设备上删除

        将设备完全关机再重新启动

打开 设置->通用->日期与时间里 将设备时间拔快一天以上
将设备再次完全关机再重新启动

此时再安装你的App可以像纯新的流程一样进行测试所有授权,


在设置中查看你的App授权选项也是全部重置。


附上注册通知的代码:


在AppDelegate的 didFinishLaunchingWithOptions方法中,添加代码:

UIApplication *app = [UIApplication sharedApplication];
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        
        if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) {
            NSLog(@"8.0注册通知");
            [app registerUserNotificationSettings:settings];
        } else {
            NSLog(@"7.0及以下 注册通知");
            [app registerForRemoteNotificationTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound];
        }

对于IOS8 ,新增了didRegisterUserNotificationSettings方法。如果要注册RemoteNotification,需要在此方法里添加注册代码:

if (IS_IOS8) {
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
否则,如果注册通知没完成,就添加

[[UIApplication sharedApplication] registerForRemoteNotifications]
会引起以下warning:

Attempting to schedule a local notification ..... with an alert but haven't received permission from the user to display alerts




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值