Friday, August 29, 2008

The most useful iPhone app I can't release

PLEASE NOTE: This technique described here was originally done for iOS 2.0. It no longer works under iOS 4. If you want to turn on Bluetooth programmatically, you can do so using the iPhone GameKit SDK. However, this does not allow you to turn Bluetooth off. It only provides a method to turn it on.


I have long since abandoned using private APIs for any of my projects, so I unfortunately can not provide any advice on how you might be able to toggle Bluetooth under iOS 4.


Here's the most simple, yet useful application I've made for the iPhone. You click on the Bluetooth® icon and Bluetooth is toggled on or off. That's it. The app even immediately exits after you click on it.

This is much simpler than how you normally have to turn Bluetooth on or off via the iPhone settings. Compare. Here's a screen shot of my app. One tap and Bluetooth turns on or off.



Now here are the four screen shots of turning Bluetooth on or off via the iPhone settings menu.









Now, counting the final click of the home button, that's 5 clicks vs. just one with my app. Granted, it's a very simple app and many other people have suggested doing this same thing. However, what is frustrating is there's no way anyone can legally give this app to anyone. The Apple iPhone SDK specifically prohibits using private framework APIs, and unfortunately, to access the Bluetooth functionality requires using the private frameworks.

Hopefully some day soon Apple will change this policy. There's a lot more useful things that can be done in these apps if Apple would just allow developers to use the private frameworks. I currently have an outstanding query into Apple's developer support regarding this issue (I get two free tech support queries with my developer license) but it's been almost a month now and Apple still hasn't responded.

Interestingly, as of today, there are actually several applications in the iTunes App Store which do make use of the private frameworks - in direct violation of the SDK license agreement. It appears the people in charge of approving apps either have no way to automatically scan an app for private framework API calls or they are turning a blind eye on it since Apple gets 30% cut of all money these applications earn.

As for me, I'm currently not willing to risk my iPhone developer license by knowingly submitting an app that is in violation of this policy.


The Bluetooth® word mark and logos are registered
trademarks owned by Bluetooth SIG, Inc. and any use of
such marks by Stormy Productions is under license. Other
trademarks and trade names are those of their respective
owners.

46 comments:

Peter said...

Very interesting! I've been trying to create an app that toggles the airplane mode feature on my non-jailbroken iphone (just for personal use) but it doesn't seem to work.

I've been trying to use dynamic linking via dlopen but I just get a NULL handle so I assume the apple sandboxing does not allow this.

Did you use dynamic linking or one of the private APIs? Have you found an API that toggles the airplanemode? I could only find a setAirplaneMode method in BluetoothManager but that did not have any effect on my phone...


Regards,
Peter

Mostly Torn said...

Hi Peter,

I am using the BluetoothManager private framework to accomplish my toggling of it on and off. From the testing I've done, the setAirplaneMode method for the Bluetooth manager is Bluetooth specific - it's not the master control for shutting down all wireless services. It does get called when you click on Airplane Mode in the Settings screen. (When enabled, it silently prevents you from turning Bluetooth on.) You can verify this by viewing the console log on the iPhone.

If you haven't looked at that, it's very useful to see what is going on behind the scenes when you run different applications or change different settings.


I haven't yet found the function for performing the system-wide Airplane mode toggling just yet. I'm wondering if accessing it via the SCPreferences API might work. It's not something I really needed to do, so I haven't really invested much time in looking into it.

Good luck!

Peter said...

Thanks for the info!

I hadn't thought about the console log, very useful!
I'll do some testing and see what I come up with...

Regards,
Peter

Anonymous said...

Yeah, this is the first app I conceived of writing when I got my iPhone. I planned to take it one step further and toggle the wifi radio, too. Or some simple combination.

Maybe one day we can do this within the bounds of the official API.

Jinny said...

Hi
Do you know how to inquiry the devices and get mac addresses using bluetooth private framework in iphone? I wonder....
Thank you

Anonymous said...

I can only join all of you in your attempts to make this kind of applications live :) I prefer unbroken iPhone (although I tried it with jailbreak and lots of custom Cydia applications) and I really dream of having legal simple prefs switching applications like the one for Bluetooth and Wi-Fi. Actually my idea of an application is having something similar to Nokia profiles (maybe even time-switchable) where you have all those simple things like ring type, bluetooth, wi-fi, etc. Pity we can't do that :((

Anonymous said...

Hi - this is almost exactly what I want...
As the iphone is such a power hungry beast, I would like to see a power management app. where all the various connections can be turned on/off on one simple screen:
- 3G
- Wifi
- Bluetooth
- Locations services (GPS?)
- Airplane mode (although this is easily reached directly in settings)
- anything i've missed?

if apple allow whatever programming method is required to do this, i would be one of the first to download the app!

St0rM said...

Would be SO good to have it legally released... SOO good...

Anonymous said...

How about an app that allows you to manage/toggle all of the following:

Bluetooth
Location Manager
3G
Brightness

all in 1 or 2 taps?

Thanks,
TS

Anonymous said...

And if you could make it location aware...that would be truly great! I want something that will turn wifi on when in the office and at home. Off as soon as I drive away from either and at night after a set time. This should be a built in functionality or at the least, allowed through 3rd party apps. Here's hoping Apple sees the utility in this.

Lisa said...

I agree about the location awareness idea. I have just switched from a windows mobile device on which I'd installed an app that recognized what mobile cell the phone was connected to and changed settings accordingly. I had it set to turn wifi on but everything else off (including ringer) at home and work but to switch wifi off and bluetooth on when I left these cells for the car. It was so useful but I guess apple's policy prohibits anything like it for the iphone at present?

KayZee Solutions said...

Great idea. If you are planning on selling this app then I understand your frustration. However, since you are a developer, you can put this app on your iPhone (and hand it out to any friends through Ad Hoc) and move on to something bigger/better :)

Anonymous said...

Interesting article. I was looking for this application without jail breaking the phone. It seems Apple has crippled the phone in some areas, like this one. Location aware features for settings would be useful and definitely reduce some of the frustration of toggling settings so you can make it a full day on battery.

thecoleorton said...

The features we've all noted in the above comments are covered in the Android app, "Locale".

http://code.google.com/android/adc_gallery/app.html?id=25

It's too bad there isn't an API to turn off wifi, bluetooth, set a different ringer, turn your phone to vibrate - based on your location.

Has Apple responded to your question about the availability of such API?

Cole

Anonymous said...

I like the idea of a time/location-sensitive profile app that also allows for quick and basic toggles.

As an IT admin, I have several folks who need to use the iPhone in different ways in different environments. The previous "smartphones" we had couldn't do much, didn't suck down much data, and had decent battery life so there was little need for location/time-based profiles.

Fingers crossed that Apple either adds functionality or loosens API constraints...

Brian said...

I've been trying to create an application that provides a switch for WiFi, Bluetooth, and screen brightness, along with a graph of the battery usage since the last charge with percentage and estimated time remaining. I think it would be a very useful app, but unfortunately I won't get it completed unless Apple changes their mind and allows it (I was wondering why there wasn't any good power management apps). Oh well, on to something else.

Ravi said...

I have to echo Anon's enthusiasm. I desperately need this app. Would pay 2.99 or more!

robfol said...

I would buy this too! even at $5.00. Apple's implementation of switching these elements is idiotic. Do their developers sit on their behinds all day next to a charger? One Energy Saving pref pane, with location awareness please

Amrish said...

Hi -

I was planning on writing a similar app myself. I have never programmed for the iPhone, but have coded in Javascript and VB.
Would this specific app be easy to develop?
What software tools are required?

Thanks!

Chris Miles said...

If you can't distribute your app via the App Store would you consider releasing some of the code so other devs can see how you did it and whip up their own apps for private use? Just some details on the private frameworks would be useful, to save us some time.

Separately, have you considered releasing the app via Cydia (paid or free) for jailbroken devices?

Sean said...

can you post the source code how to use BluetoothManager? turn on/off, discover remote devices would be great, too.

Anonymous said...

This would be very handy... any word from Apple regarding your queries?

lukie said...

Hey I would love to be able to have the code ir the app to turn wifi on and off on my iPhone.
If anyone is willing to send me it\them I wouldn't be able to thank them enough.my email is googthings@gmail.com.

North Coast Photography said...

I so want this app - turning BT on and off drives me BANANAS.

Mark said...

Not sure if this thread is even still viewed, been almost two months since the last comment, but I came across it and thought I'd ask something of you.
I had the idea to just turn bluetooth off when powered by an outside source, for the sake of use in my car, just as a simpler way of knowing when it would be in my car, rather than location aware.
If anyone knows how to set this up, or has already, please email me at bicboy.2000 (at) gmail.com

Thanks very much!

Anonymous said...

Pussy! Apple won't cut your nuts off, I promise.

Anonymous said...

Search the app store for bluetoothme, this app will turn BT on with just one click.

Travis said...

I'd love to know how to make this app myself too! Plz let me know!!

Ferdinand G Rios said...

Is it possible that you might share the source code for this so that other devs can see how it was done?

Mostly Torn said...

The code is literally just a few lines. I'll post an update with it later today.


One thing to be aware of is this will definitely NOT be approved by Apple if you try to include it in an app for the App Store.

Travis said...

are you going to post the program or the code? I have no clue what to do with just the code...

Beekink said...

Hi Mostly Torn, did you in the end post the code anywhere? I'm really looking for a way to toggle bluetooth easily. Now I know why I can't find this. Hopefully you can share the code somehow. Thanks in advance.

Cire Zerep said...

I found this post by searching for a Bluetooth Toggle app for iPhone. Somebody already mentioned it before, but there's an app (in the store) from Japan called 'BluetoothMe' that is very small (~50k download) that enables you to receive mail or something from the 'MailMe' app from the same company.

That being said, the most useful feature of this app is that if Bluetooth is turned off, the first thing it does when you run it is it prompts you with a dialog box that allow you to turn on Bluetooth. Then you can just exit the app.

Unfortunately, it's not really a 'toggle' because it can't turn off Bluetooth, but it is handy for turning ON Bluetooth using less taps than the Apple settings (built-in) method.

Anonymous said...

could you post the source code please?

thanks

Mostly Torn said...

Here's the code. Again, this will NOT be approved by Apple if you use it in an app.

#import "BluetoothManager/BluetoothManager.h"

int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
BluetoothManager *bt;

bt = [[BluetoothManager alloc] init];

if ([bt enabled]){
[bt setEnabled:FALSE];
}else{
[bt setEnabled:TRUE];
}

[bt release];
[pool release];
return 0;
}

Anonymous said...

Hello, can you say me how I can find BluetoothManager.h and how to import in my project?

Anonymous said...

I've just tried to build your code, which compiles without issue, but it does not do anything. I added a front end so I could have a button to switch it on/off and a popup telling me its current condition and it always thinks the BT radio is not enabled. BTW I'm using the latest XCode for iPhone OS 4.0.

Many thanks

Dave

Anonymous said...

Hello Dave, can you help me to find the private framework to use? I'm new on the iphone development and I don't know where is it...

sparkplug said...

The public framework headers can be pulled from the binary files via the utility at http://www.codethecode.com/projects/class-dump/

The headers are what you include in your application.

Dave

Anonymous said...

Hello, can anyone upload the working code for the BT ON/OFF APP.....:-)

Very very thanks


its not work my app...hmmm

Anonymous said...

Wouldn't it be great if you could schedule bluetooth on/off? I only use it at weekends in our family car and it drains battery during the week. I would pay for that. Why won't apple allow it?

Anonymous said...

Can anyone else get the BT on/off code working? It doesn't work for me, using OS 4.0. Any help is appreciated. Thx.

David said...

Please help. I am a new developer, and am trying to make this code work with SDK 4.0. I can get it to compile and link but once on the phone, the app does nothing. I am betting it has something to do with changes from SDK 4 from 3, but all my efforts to find out how to fix it have failed. Can anyone please help?

Thanks,
--David

Anonymous said...

Same problem! Doesn't work using iOS4.
NSLog(@"%@", [btmgr enabled]?@"YES":@"NO"); //"NO"
[btmgr setEnabled:![btmgr enabled]];
NSLog(@"%@", [btmgr enabled]?@"YES":@"NO"); //"NO"

Any ideas?
THX
Peter

David said...

Peter,

I tried sending Email directly to the Stormy Production team and no reply. Interestingly enough, the app referenced above "BluetoothMe" which does turn on Bluetooth was updated for iOS4 and they were able to do it. I also tried Emailing that company (Japanese) and they also didn't reply.

Clearly this can be done, but no one seems willing to step up and help.

Please -- some developer out there knows what the problem is and how to solve it. Please help us. Thx!

Mostly Torn said...

The BluetoothMe app simply uses the iPhone GameKit to turn on Bluetooth. It does not, however allow turning off Bluetooth since GameKit does not provide a way to do this.

As for using private APIs, I have no idea what is needed to do this under iOS 4. I have not needed to do this, so have not investigated it in a couple of years.

Sorry.


All content copyright © 2009  Brian Stormont, unless otherwise noted.   All rights reserved.