Reputation: 1795
I just want to know whether is it possible to switch on bluetooth programmatically on iPhone?
Upvotes: 1
Views: 1707
Reputation: 6015
it is possible to switch on/off the Bluetooth by using the below lines of code , but since it access private frameworks of Apple, your App may reject in App store push
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
#if TARGET_IPHONE_SIMULATOR
exit( EXIT_SUCCESS ) ;
#else
/* this works in iOS 4.2.3 */
Class BluetoothManager = objc_getClass( "BluetoothManager" ) ;
id btCont = [BluetoothManager sharedInstance] ;
[self performSelector:@selector(toggle:) withObject:btCont afterDelay:1.0f] ;
#endif
return YES ;
}
#if TARGET_IPHONE_SIMULATOR
#else
- (void)toggle:(id)btCont
{
BOOL currentState = [btCont enabled] ;
[btCont setEnabled:!currentState] ;
[btCont setPowered:!currentState] ;
}
#endif
Upvotes: 3
Reputation: 42554
For some reason David Schiefer answered your question as two comments, so I'm just gonna repeat what he said:
That's a very general question - at this point in time, you can use Bluetooth for GameKit (multiplayer games) and wireless headsets. iPhone -> non-iPhone sending of data is not supported. You can however use GameKit to send data to other iOS devices.
since you've changed your question: GameKit will enable Bluetooth once the dialog for connection pops up and Bluetooth is selected.
Upvotes: 0