註冊本地通知
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];
這將在第一次呼叫時顯示警告:
無論使用者選擇什麼,警報都不會再次顯示,使用者必須在設定中啟動更改。