【问题标题】:Switch On bluetooth programmatically on iPhone在 iPhone 上以编程方式打开蓝牙
【发布时间】:2011-03-14 13:08:20
【问题描述】:

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

【问题讨论】:

  • 这是一个非常普遍的问题——此时,您可以将蓝牙用于 GameKit(多人游戏)和无线耳机。 iPhone -> 不支持非 iPhone 发送数据。但是,您可以使用 GameKit 将数据发送到其他 iOS 设备。
  • 因为您已更改问题:一旦弹出连接对话框并选择蓝牙,GameKit 将启用蓝牙。

标签: ios iphone bluetooth


【解决方案1】:

可以通过以下代码来开启/关闭蓝牙,但是由于它访问的是Apple的私有框架,你的App可能会在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

【讨论】:

    【解决方案2】:

    出于某种原因,David Schiefer 作为两个 cmets 回答了您的问题,所以我将重复他所说的话:

    这是一个非常普遍的问题 - 目前,您可以将蓝牙用于 GameKit(多人游戏)和无线耳机。 iPhone -> 不支持非 iPhone 发送数据。但是,您可以使用 GameKit 将数据发送到其他 iOS 设备。

    因为您已更改问题:一旦弹出连接对话框并选择蓝牙,GameKit 将启用蓝牙。

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 1970-01-01
      • 2012-03-01
      相关资源
      最近更新 更多