Categories

Getting started with Bluetooth Mobile Multiplayer

Unity Asset Store

You can buy an asset in the Unity Asset Store After purchasing the asset, you need to import it into the project. You can do this via Window->Asset Store or via Window->Package Manager in the My Assets category

Permissions

To work with Bluetooth on Android and iOS mobile systems, you must grant permission to use this service. Plugins automatically add the necessary permissions to AndroidManifest.xml or Info.plist for Android and iOS respectively. Now I will tell you more about the permissions being added for each platform.

Android:

Here are the permissions that are required to work with Bluetooth services.

<manifest>
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<!-- To search for Bluetooth devices, you need to add a search and location permission. (3 options, for devices below version 9 of Android, for devices up to version 11 and for version 12 of Android) -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

<!-- Needed your app makes the device discoverable to Bluetooth devices -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>

<!-- Needed your app communicates with already-paired Bluetooth devices -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
...
</manifest>

IOS:

To work with bluetooth in iOS, you need to add two keys to info.plist:

  • NSBluetoothAlwaysUsageDescription
  • NSBluetoothPeripheralUsageDescription

The first is required for devices above IOS 13, and the second for devices with IOS 13 and below