iosswiftiphoneios15

Redirect to phone settings like Wifi/bluetooth from within iOS app


I know this is a common question but since there are lots of things changing with each ios update , curious to ask this again.

I have a requirement in iOS app (implemented using ionic framework) , where there must be an option to go to Bluetooth settings of the iphone from within the app so that the user can turn it on/off.

I have read several articles saying that Apple may reject apps trying to access phone settings and it is not advisable to access phone settings through app. Can someone clarify if this still holds true with latest iOS versions and should I never try to do this in future?


Solution

  • You cannot open the Bluetooth settings by using

    App-Prefs:root=Bluetooth
    

    The issue is that Apple does not allow us to use non-public APIs anymore and you maybe at risk of getting your developer program cancelled if you try to do so.

    All you can do is open the iPhone settings in general by using this code:

    extension UIApplication {
    
        static func openAppSettings(completion: @escaping (_ isSuccess: Bool) -> ()) {
            guard let url = URL(string: UIApplication.openSettingsURLString) else {
                completion(false)
                return
            }
            
            UIApplication.shared.open(url) { isSuccess in
                completion(isSuccess)
            }
        }
    }
    

    Usage:

     UIApplication.openAppSettings { isSuccess in
            if isSuccess == false {
                    //Display error
            }
       }