注册本地通知

Version >= iOS 8

要向用户显示本地通知,你必须使用设备注册你的应用:

迅速

let settings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)

Objective-C

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

这将在第一次调用时显示警告:

StackOverflow 文档

无论用户选择什么,警报都不会再次显示,用户必须在设置中启动更改。