ios - 在iPhone上以编程方式打开蓝牙

标签 ios iphone bluetooth

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

最佳答案

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

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

关于ios - 在iPhone上以编程方式打开蓝牙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5298974/

相关文章:

ios - 尝试学习 objective-c 委托(delegate)。为什么我的示例项目不起作用?

iphone - 如何在 iPhone 中使用移动和缩放 UIImagePickerController?

iphone - iOS 7 更新对我的应用的影响

ios - Peer2Peer CouchbaseListener

android - 在配对状态下捕获蓝牙

ios - swift中的行控制语句

ios - UILocalNotification如何在屏幕锁定时显示应用程序图标

ios - 在 iOS 6 中以编程方式打开 map 应用

iphone - NSDecimal、NSDecimalNumber、CFNumber 之间的正确选择是什么?

android - onLeScan 永远不会被称为 android