有没有办法以编程方式在iPhone中打开/关闭蓝牙? [英] Is there any way to switch on/off bluetooth in iPhone programatically?

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

问题描述

在我的应用程序中,我想打开/关闭iPhone Bluetooth.i m使用sdk 4.3..i对蓝牙管理器框架有一些了解,但它不适用于4.3 ..任何想法?或者我们可以以编程方式确定蓝牙是否开启?

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 its not working in 4.3..any ideas ? or can we programatically determine whether Bluetooth is ON/OFF ?

推荐答案

- (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天全站免登陆