initialize method
- required String appId,
- ApiEnv? apiEnv,
- String? advertiserId,
- double? xyDragDistanceAllowed,
- String? storeId,
- void onAddToListTriggered(
- List<
DetailedListItem> items
- List<
- void onOutOfAppPayloadAvailable(
- List<
OutOfAppDataPayload> payloads
- List<
Initializes the session for the AdAdapted API and sets up the SDK.
@param appId - The app ID provided by the client. @param apiEnv - The API environment. Defaults to production. @param advertiserId - A custom advertiser ID to replace the IDFA. iOS only, matching the other SDKs. @param xyDragDistanceAllowed - The touch sensitivity of an ad zone in both the X and Y directions. Used to tell a tap on a zone from a scroll: a touch that travels less than this in both directions is a tap. @param storeId - The store to target ads for, if targeting ads by store. @param onAddToListTriggered - Called when "add to list" items are clicked in a zone that has no handler of its own. @param onOutOfAppPayloadAvailable - Called when an "add to list" occurs by means of an "out of app" data payload.
Implementation
Future<void> initialize({
required String appId,
ApiEnv? apiEnv,
String? advertiserId,
double? xyDragDistanceAllowed,
String? storeId,
void Function(List<DetailedListItem> items)? onAddToListTriggered,
void Function(List<OutOfAppDataPayload> payloads)?
onOutOfAppPayloadAvailable,
}) async {
_appId = appId;
// All three backends follow the environment the caller asked for.
_resolveApiEnvironments(apiEnv);
if (xyDragDistanceAllowed != null) {
_xyAdZoneDragDistanceAllowed = xyDragDistanceAllowed;
}
if (onAddToListTriggered != null) {
_onAddToListTriggered = onAddToListTriggered;
}
if (onOutOfAppPayloadAvailable != null) {
_onOutOfAppPayloadAvailable = onOutOfAppPayloadAvailable;
}
if (storeId != null) {
_storeId = storeId;
}
// A previous cycle's client is released before a new one replaces it, so a
// host that calls initialize() twice does not leak the connections the
// first one opened.
_api?.close();
_api = AdadaptedApiRequests(client: _httpClient);
var deviceInfo = await _deviceInfoChannel.getDeviceInfo();
_deviceOs = deviceInfo.systemName.contains('ios')
? DeviceOS.ios
: DeviceOS.android;
// Pass custom advertiserId - iOS only, matching the other SDKs.
if (_deviceOs == DeviceOS.ios && advertiserId != null) {
deviceInfo = deviceInfo.copyWith(udid: advertiserId);
}
_deviceInfo = deviceInfo;
// There is no session request any more. The session is minted here and
// lives only for as long as this isolate does, exactly as Android's
// SessionClient does, so relaunching the app always starts a new session.
_createOrResumeSession();
// Ad zones read their session and device info from here.
_registerAdRequestContext();
// Get all possible keyword intercept values. We don't need to wait for this
// to complete prior to resolving initialization.
unawaited(_getKeywordIntercepts());
// Make the initial call to the Payload data server to see if the user has
// any outstanding items to be added to list.
unawaited(_getPayloadItemData());
// Any observer from a previous initialize() goes first, so a second call
// replaces it instead of stacking on top.
_removeLifecycleObserver();
final observer = _AppLifecycleObserver(_handleAppLifecycleChange);
_lifecycleObserver = observer;
WidgetsBinding.instance.addObserver(observer);
}