start method
Starts beacon advertising.
Before starting you must set _uuid
.
For the default layout, parameters _majorId
, _minorId
are also required.
Other parameters as _identifier
, _transmissionPower
, _advertiseMode
, _layout
, _manufacturerId
are optional.
For Android, beacon layout is by default set to AltBeacon (check more details here: AltBeacon - Transmitting as a Beacon). On Android system, it's required to have Bluetooth turn on and to give app permission to location.
For iOS, beacon is broadcasting as an iBeacon (check more details here: Turning an iOS Device into an iBeacon) Note that according to the article: "After advertising your app as a beacon, your app must continue running in the foreground to broadcast the needed Bluetooth signals. If the user quits the app, the system stops advertising the device as a peripheral over Bluetooth.
Implementation
Future<void> start() async {
if (_uuid == null || _uuid!.isEmpty) {
throw new IllegalArgumentException("Illegal arguments! UUID must not be null or empty: UUID: $_uuid");
}
if ((_layout == null || _layout == ALTBEACON_LAYOUT) && (_majorId == null || _minorId == null)) {
throw new IllegalArgumentException("Illegal arguments! MajorId and minorId must not be null or empty: "
"majorId: $_majorId, minorId: $_minorId");
}
Map params = <String, dynamic>{
"uuid": _uuid,
"majorId": _majorId,
"minorId": _minorId,
"transmissionPower": _transmissionPower,
"advertiseMode": _advertiseMode,
"identifier": _identifier,
"layout": _layout,
"manufacturerId": _manufacturerId,
"extraData": _extraData,
};
await _methodChannel.invokeMethod('start', params);
}