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

后端 未结 2 1412
慢半拍i
慢半拍i 2021-01-16 15:32

In my application I want to switch on/off iPhone Bluetooth.i m using sdk 4.3..I got some idea regarding Bluetooth manager framework, but it\'s not working in 4.3..any ideas?

相关标签:
2条回答
  • 2021-01-16 16:24
    - (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 讨论(0)
  • 2021-01-16 16:26

    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.

    0 讨论(0)
提交回复
热议问题