I am thinking about writing my first little iPhone app using Xojo but need to be able to turn Airplane Mode On/Off and Bluetooth On/Off, can someone point me in the right direction as to how I might be able to do this from within a Xojo app. Thanks
Apple doesn’t permit this programmatically
There no public API for this and if you delve into using private frameworks you wont be able to distribute your app via the store
Msgbox “please turn off Airplane Mode”
If an app turned it off without asking , it would be binned in 13 seconds.
As stated above you cannot change those options programmatically. I use the below code in the action event of a button to open up Settings to the WIFI page. I have not tried but would assume you could set the root=Bluetooth and take them to the Bluetooth settings. Also our app is not going through the app store as its an Enterprise app. I am not sure if this would be acceptable in code for the App Store.
[code]Dim b as Boolean
[code]Public Function ShowURL(url As Text) as Boolean
// NSString* launchUrl = @“http://www.xojo.com/”;
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
Declare Function NSClassFromString Lib “Foundation” (name As CFStringRef) As Ptr
Declare Function sharedApplication Lib “UIKit” Selector “sharedApplication” (obj As Ptr) As Ptr
Dim sharedApp As Ptr = sharedApplication(NSClassFromString(“UIApplication”))
Declare Function URLWithString Lib “Foundation” Selector “URLWithString:” ( id As Ptr, URLString As CFStringRef ) As Ptr
Dim nsURL As Ptr = URLWithString(NSClassFromString(“NSURL”), url)
Declare Function openURL Lib “UIKit” Selector “openURL:” (id As Ptr, nsurl As Ptr) As Boolean
Return openURL(sharedApp, nsURL)
[quote=338356:@Stephen Koger]As stated above you cannot change those options programmatically. I use the below code in the action event of a button to open up Settings to the WIFI page. I have not tried but would assume you could set the root=Bluetooth and take them to the Bluetooth settings. Also our app is not going through the app store as its an Enterprise app. I am not sure if this would be acceptable in code for the App Store.
[code]Dim b as Boolean
This is now considered a “private API” and as such is grounds for app rejection (if caught by Apple). See the Apple employee response in the second message of this thread .
If you are doing an Enterprise or private app, then private APIs do not go through a review process. But how you make this particular API work varies by iOS release. Up through iOS 5.0 the Bluetooth page was at:
but as of iOS 7 is at:
“prefs:root=Bluetooth” (I think iOS 7,8,9) or “App-Prefs:root=Bluetooth” (I think iOS 10 – don’t know about iOS 11)
I’ve seen it suggested to first use canOpenURL(url) with “prefs:” to test if it is possible, then if that fails try “App-Prefs:” prefix.
And Apple could take away this ability at anytime (like they did in iOS 5.1 and iOS 6.x) or change the prefix again (like they did in iOS10). Since it is not an officially supported API, you can’t complain about this to Apple either. It seems their changes have been intentional. And if you did get it into the App Store, you might find a future upgrade rejected. So for a public app, I’d recommend you do as Jeff suggests and just alert the user.
This is one of those Apple decisions which I do not understand. I can understand why they block actually turning it on and off programatically (although I once had code that did up to iOS 4 via private APIs). But I really don’t see the danger in letting an app direct you to the proper Settings app panel. Glad nearly everything I do is Enterprise apps.