ios - 以编程方式导航到手机上应用程序的推送通知设置
<p><p>我有一个带有按钮的示例应用程序。点击按钮应该让用户为我的应用推送通知服务,以便能够禁用或启用它们。
我知道如何使用此示例代码进入常规设置,但我认为通知可能需要一些额外的参数,例如 bundleId。</p>
<p><strong>我的问题更多是关于我的应用的推送通知的 URL,而不仅仅是一般设置,如下面的代码示例所示</strong></p>
<p>示例代码:</p>
<pre><code>@IBAction func pushNotificationSettings(button: UIButton) {
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
print("Settings opened: \(success)") // Prints true
})
} else {
// Fallback on earlier versions
}
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>IOS 10 或以上版本</p>
<pre><code> UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
// Notifications are allowed
}
else {
// Either denied or notDetermined
let alertController = UIAlertController(title: nil, message: "Do you want to change notifications settings?", preferredStyle: .alert)
let action1 = UIAlertAction(title: "Settings", style: .default) { (action:UIAlertAction) in
if let appSettings = NSURL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(appSettings as URL, options: [:], completionHandler: nil)
}
}
let action2 = UIAlertAction(title: "Cancel", style: .cancel) { (action:UIAlertAction) in
}
alertController.addAction(action1)
alertController.addAction(action2)
self.present(alertController, animated: true, completion: nil)
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 以编程方式导航到手机上应用程序的推送通知设置,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/47834503/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/47834503/
</a>
</p>
页:
[1]