您好,欢迎来到知库网。
搜索
您的当前位置:首页请求用户的授权

请求用户的授权

来源:知库网

苹果在iOS 8之后将应用程序的通知设置为用户可选择 ,因此可以在AppDelegate的如下方法中请求用户的授权,用户同意之后即可向用户发送通知.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0)

{

UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

}

else

{

UIRemoteNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];

}

return YES;

}

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务