开发者

Is there any way to switch on/off bluetooth in iPhone programmatically?

In my application I want to switch on/off iPhone Bluetooth.i m using sdk 4.3..I got some idea rega开发者_运维知识库rding Bluetooth manager framework, but it's not working in 4.3..any ideas? or can we programmatically determine whether Bluetooth is ON/OFF?


Please note that you wouldn't be able to publish the app on the App Store because doing that must use private API.

If you still want to do that you should read this link: Is there a way to toggle bluetooth and/or wifi on and off programmatically in iOS?

Pay attention for adding GameKit framework for it to work and not using all the other thing written like adding .h files etc. unless gameKit doesn't sole all the problems.


- (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

the above lines of code i got from here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜