美文网首页
推送的权限

推送的权限

作者: adalillian | 来源:发表于2020-06-02 11:19 被阅读0次

// 自定义方法-获取用户推送通知授权

-(void)registerAutor{

    if(@available(iOS 10,*))

    {

        UNUserNotificationCenter * center =[UNUserNotificationCenter currentNotificationCenter];

        center.delegate = self;

        [center requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted,NSError * _Nullable error){

            if(granted){

                //允许推送

            }else{

                //不允许

            }

        }];

    }

    else if(@available(iOS 8,*))

    {

        UIApplication * application =[UIApplication sharedApplication];

        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];

        [application registerForRemoteNotifications];

    }

    else

    {

        UIApplication * application =[UIApplication sharedApplication];

        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];

        [application registerForRemoteNotifications];

    }

}

相关文章

网友评论

      本文标题:推送的权限

      本文链接:https://www.haomeiwen.com/subject/rlcdyqtx.html