UserNotification 1 Opening the dialog box settings notification settings

Swift3.0 // // ViewController.swift // Utility006_3.0 // // Created by KimikoWatanabe on 2016/08/24. // Copyright © 2016年 FaBo, Inc. All rights reserved. // 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 // // ViewController.swift // Utility006_2.3 // // Created by KimikoWatanabe on 2016/08/24. // Copyright © 2016年 FaBo, Inc. All rights reserved. // 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の導入

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.