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

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

问题描述

在我的应用程序中,我想使用sdk 4.3打开/关闭iPhone Bluetooth.i.我对Bluetooth Manager框架有一些了解,但在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 it's not working in 4.3..any ideas? or can we programmatically 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

我从

the above lines of code i got from here

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

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