Bluetooth Device Pairing
Prerequisites
Before you begin, ensure you have the following prerequisites:
- The latest version of Xcode
- An iOS project with a deployment target of iOS 14.0 or higher
- A Scandit Express license key. Sign up for a free trial if you don't already have a license key.
Installation
- Swift Package Manager
- CocoaPods
- Add Manually
To integrate the BLEScanner SDK into your Xcode project using Swift Package Manager, add the desired frameworks in the Package Dependencies section of your project.
Add our SPM package repository:
https://github.com/Scandit/blescanner-spm
Alternatively, if you prefer checking out git repositories via SSH:
git@github.com:Scandit/blescanner-spm.git
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. To integrate the BLEScanner SDK into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'BLEScannerSDK'
You can download the framework from:
https://ssl.scandit.com/sdk/download/scandit-blescannersdk-ios-${VERSION}.zip
replacing ${VERSION}
with the version you want to download.
Configuring the Host
To use the SDK in your source code, import it as follows:
import BLEScannerSDK
You can then use the WedgeHost
initializer to set up a host:
WedgeHost(
hostName: String,
projectCode: String,
baseUrl: String,
eventCallback: (WedgeHostEvent) -> Void
)
- hostName: The name you specify for the host.
- projectCode: Your Scandit Express project code provided in the dashboard.
- baseUrl: The base URL for the QR code that will be generated. You can use this to directly open your app by specifying a universal link. For example, if you want your host to redirect users to Scandit Express, you can specify
https://express.scandit.com/bluetooth
orscanditExpress://bluetooth
. - eventCallback: The callback for events sent to the host (more details below).
The host can provide you with the connection QR code as a UIImage
using:
host.makeQRCode().generateQRCode()
Receiving Events
Hosts receive events in the eventCallback
. Here's how an event is defined:
public struct WedgeHostEvent {
public let eventType: BLEScannerSDK.WedgeHostEventType
public let data: String?
}
public enum WedgeHostEventType: Int {
case NONE
case ADV_STARTED // ADV stands for advertising Bluetooth services
case ADV_STOPPED
case ADV_ABORTED
case DEVICE_NAME_SET
case DEVICE_BARCODE_RECEIVED
case DEVICE_DISCONNECTED
}
For example, when the host successfully receives a barcode, the WedgeHostEvent
will look like this:
WedgeHostEvent(eventType: .DEVICE_BARCODE_RECEIVED, data: "barcode data")
Debugging the Host
You will need to run the host on a physical device since Bluetooth functionality does not work on the simulator.