2011-03-14 204 views
1

我是iphone开发新手,我只想知道是否可以通过编程方式在蓝牙上开关?以编程方式打开蓝牙

+0

这是一个非常一般问题 - 在这个时候,你可以使用蓝牙GameKit(多人游戏)和无线耳机。 iPhone - >非iPhone发送数据不受支持。但是,您可以使用GameKit将数据发送到其他iOS设备。 – Pripyat 2011-03-14 13:11:53

+0

因为您已更改您的问题:一旦连接对话框弹出并选择蓝牙,GameKit将启用蓝牙。 – Pripyat 2011-03-14 13:12:31

回答

3

可以通过使用代码下面的行/关闭蓝牙开关,但由于访问苹果的私有框架,你的应用可以在App store的推拒绝

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

出于某种原因,大卫·席费尔回答了你的问题,作为两个意见,所以我只是要重复他说的话:

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

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

相关问题