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
网友评论