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

发布于 2024-10-22 00:12:23 字数 37 浏览 1 评论 0原文

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

I just want to know whether is it possible to switch on bluetooth programmatically on iPhone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙温凉少女 2024-10-29 00:12:23

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

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

it is possible to switch on/off the Bluetooth by using the below lines of code , but since it access private frameworks of Apple, your App may reject in 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
述情 2024-10-29 00:12:23

出于某种原因,大卫·希弗(David Schiefer)以两条评论回答了你的问题,所以我只是重复他所说的话:

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

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

For some reason David Schiefer answered your question as two comments, so I'm just gonna repeat what he said:

That's a very general question - at this point in time, you can use Bluetooth for GameKit (multiplayer games) and wireless headsets. iPhone -> non-iPhone sending of data is not supported. You can however use GameKit to send data to other iOS devices.

since you've changed your question: GameKit will enable Bluetooth once the dialog for connection pops up and Bluetooth is selected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文