推送的权限

2020-06-02  本文已影响0人  adalillian

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

-(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];

    }

}

上一篇 下一篇

猜你喜欢

热点阅读