美文网首页
Swift 3 打开系统设置界面

Swift 3 打开系统设置界面

作者: 船长_ | 来源:发表于2017-05-22 16:03 被阅读899次
let urlObj = URL(string:UIApplicationOpenSettingsURLString)
 if #available(iOS 10.0, *) {
       UIApplication.shared.open(urlObj! as URL, options: [ : ], completionHandler: { Success in
                
})} else {
       UIApplication.shared.openURL(urlObj!)
 }
override func viewDidLoad() {
        super.viewDidLoad()
        // 监听app进入前台
        NotificationCenter.default.addObserver(self, selector: #selector(appEnterForeground), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)
    }

@objc fileprivate func appEnterForeground() {
        let settings = UIApplication.shared.currentUserNotificationSettings

        if settings?.types == UIUserNotificationType.init(rawValue: 0) {
            self.notiSwitch.setOn(false, animated: false)
        }else{
            self.notiSwitch.setOn(true, animated: false)
        }
    }

app接远程推送的时候,为了方便用户打开推送,在通知界面加了个开关,可直接打开系统设置界面,如图

demo.png

相关文章

网友评论

      本文标题:Swift 3 打开系统设置界面

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