gpt4 book ai didi

ios - 以编程方式导航到手机上应用程序的推送通知设置

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:05:44 27 4
gpt4 key购买 nike

我有一个带按钮的示例应用程序。单击按钮应该让用户为我的应用推送通知服务,以便能够禁用或启用它们。我知道如何使用此示例代码进行常规设置,但我认为对于通知,您可能需要一些额外的参数,例如 bundleId。

我的问题更多是关于我的应用推送通知的 URL,而不仅仅是常规设置,如下面的代码示例所示

示例代码:

@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
}
}
}

最佳答案

iOS 10以上版本

 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)
}
}

关于ios - 以编程方式导航到手机上应用程序的推送通知设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47834503/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com