通知設定のダイアログ設定を開く

Swift3.0
import UIKit
import UserNotifications
class ViewController: UIViewController,UIApplicationDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let center:UNUserNotificationCenter = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.badge], completionHandler: {(permit, error) in
if permit {
print("通知が許可されました")
}else {
print("通知が拒否されました")
}
})
}
}
Swift 2.3
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}
}
2.3と3.0の差分
- UIColorの参照方法が変更(UIColor.grayColor()->UIColor.gray)
- CGRect,CGPointの初期化方法の変更(CGRectMake,CGPointMakeの廃止)
- 従来のUIApplicationへの許可の申請が非推奨に。UserNotification frameworkの導入
Reference
- UNUserNotificationCenter Class
- UIApplication Class