android - iOS 上的蓝牙连接

标签 android ios bluetooth android-bluetooth ios-bluetooth

我们正在尝试观察蓝牙设备何时与 iPhone 连接和断开。我们本质上希望在某些感兴趣的设备连接时使用react(不一定在前台)。在 Android 中,您可以收到 ACL_CONNECTEDACL_DISCONNECTED Action 。

iOS 上的这种行为相当于什么?

我先查看了 CoreBluetooth,然后发现它用于低功耗蓝牙,然后查看了 ExternalAccessory,但它只显示 the picker 中的 MFI 设备并且似乎要求用户通过选择器。我们发现唯一可行的方法是 go through Apple's BluetoothManager itself ,根据 AppStore guidelines 禁止的在第 2.5 节中,大概是这样他们可以完全控制苹果生态系统。


等效的 Android 代码:

MyReceiver.java

public class MyReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(BluetoothDevice.ACL_CONNECTED)) {
      //do stuff
    } else if (intent.getAction().equals(BluetoothDevice.ACL_DISCONNECTED)) {
      //do stuff
    }
  }

}

AndroidManifext.xml

<receiver
  android:name="com.myapp.MyReceiver"
  android:exported="true"
  android:enabled="true"
  android:label="MyReceiver">
  <intent-filters>
      <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
      <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
    </intent-filters>
</receiver>

最佳答案

published a demo app called Beetee它显示了蓝牙经典在 iOS 上的工作方式以及全局事件是什么。但是这个私有(private)框架不是 AppStore 的投诉!

关于android - iOS 上的蓝牙连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30382012/

相关文章:

ios - 如何使用 SpriteKit 检测节点是否离开屏幕

android - 接收器生命周期 - 在 onResume() 中重新注册时崩溃

linux - 通过蓝牙发送消息,无需配对 Linux

java - 如何从数据库方案中的特定 Realm 文件中排除 Realm 模型类?

android - build.gradle 在 ionic cordova 构建后恢复到旧配置

Android TV - Leanback 库如何向 VideoSupportFragmentGlueHost 添加更多按钮

android - 在 SearchView 上显示错误消息

c# - UIButton 在相机流中不可见 (Xamarin.iOS)

ios - AFNetworking 内存不足问题

ios - 我们如何知道 iPad 使用的是蓝牙键盘还是设备虚拟键盘?