【发布时间】:2015-08-03 14:37:49
【问题描述】:
我们正在尝试观察蓝牙设备何时与 iPhone 连接和断开连接。当某些感兴趣的设备连接时,我们本质上想要做出反应(不一定在前台)。在 Android 中,您可以接收 ACL_CONNECTED 和 ACL_DISCONNECTED 操作。
在 iOS 上与此行为等效的是什么?
我首先查看CoreBluetooth,然后发现它是用于蓝牙LE,然后查看ExternalAccessory,但它只显示the picker 中的MFI 设备,并且似乎需要用户通过选择器。我们发现唯一可行的方法是go through Apple's BluetoothManager itself,这是根据第 2.5 节中的AppStore guidelines 禁止的,大概是为了让他们可以完全控制 Apple 生态系统。
等效的 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>
【问题讨论】:
标签: android ios bluetooth android-bluetooth ios-bluetooth