美文网首页iOS 开发
请求用户的授权

请求用户的授权

作者: hncjliyingjie | 来源:发表于2016-06-22 21:40 被阅读32次

苹果在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;

}

相关文章

网友评论

    本文标题:请求用户的授权

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