【发布时间】:2011-09-29 12:17:18
【问题描述】:
在我的应用程序中,我想使用 sdk 4.3 打开/关闭 iPhone 蓝牙。我对蓝牙管理器框架有一些想法,但它在 4.3 中不起作用。有什么想法吗?或者我们可以通过编程方式确定蓝牙是否开启/关闭?
【问题讨论】:
-
在 iOS 7 中是否有任何公共 API 可用于执行此操作?
标签: iphone objective-c ios ios4
在我的应用程序中,我想使用 sdk 4.3 打开/关闭 iPhone 蓝牙。我对蓝牙管理器框架有一些想法,但它在 4.3 中不起作用。有什么想法吗?或者我们可以通过编程方式确定蓝牙是否开启/关闭?
【问题讨论】:
标签: iphone objective-c ios ios4
请注意,您将无法在 App Store 上发布应用,因为这样做必须使用私有 API。
如果您仍想这样做,您应该阅读此链接: Is there a way to toggle bluetooth and/or wifi on and off programmatically in iOS?
注意添加 GameKit 框架以使其工作,而不是使用所有其他编写的东西,例如添加 .h 文件等,除非 gameKit 不能解决所有问题。
【讨论】:
- (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
我从here得到的上述代码行
【讨论】: