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

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-1 15:22   121   0

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

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

方法一:

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

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


方法二:

将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 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP