initialize method

  1. @override
Future<bool> initialize({
  1. NearbyInitializeData data = const NearbyInitializeData(),
})
override

Initializes MCNearbyServiceAdvertiser and MCNearbyServiceBrowser to allow this device to be both.

Creates MCPeerID for this device.

The name of the device on the network can be specified on initialization via the parameter data.

NearbyInitializeData.iosDeviceName will be passed to the platform as initial name. If a new name is not passed, the previous name stored in UserDefaults will be used. If there is no saved name, UIDevice.current.name will be used.

Implementation

@override
Future<bool> initialize({
  NearbyInitializeData data = const NearbyInitializeData(),
}) async {
  final result = await NearbyServiceIOSPlatform.instance.initialize(
    data.iosDeviceName,
  );

  _logResult(
    result,
    onSuccess: 'Initialized ${data.iosDeviceName}',
    onError: 'Failed to initialize ${data.iosDeviceName}',
  );
  return result;
}