在iPhone上以编程方式打开蓝牙 [英] Switch On bluetooth programmatically on iPhone

查看:83
本文介绍了在iPhone上以编程方式打开蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道是否可以在iPhone上以编程方式打开蓝牙?

I just want to know whether is it possible to switch on bluetooth programmatically on iPhone?

推荐答案

可以使用以下代码行打开/关闭蓝牙,但是由于它访问Apple的私有框架,因此您的App可能会在App中被拒绝商店推送

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

这篇关于在iPhone上以编程方式打开蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆