Opening app's notification settings in the settings app

前端 未结 3 948
心在旅途
心在旅途 2020-12-18 21:13

In the case that a user may accidentally declines to receive notifications and wants to turn notifications later, how can I use an NSURL to open the IOS Settings App to my a

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 22:00

    I found the answer to this question (albeit helpful) has a bit too much assumed logic. Here is a plain and simple Swift 5 implementation if anyone else stumbles upon this question:

    if let bundleIdentifier = Bundle.main.bundleIdentifier, let appSettings = URL(string: UIApplication.openSettingsURLString + bundleIdentifier) {
        if UIApplication.shared.canOpenURL(appSettings) {
            UIApplication.shared.open(appSettings)
        }
    }
    

提交回复
热议问题