init static method
Implementation
static Future<bool> init(String appKey, [NIMSDKOptions? options]) async {
IMKitClient.appKey = appKey;
XKitReporter().init(appKey: appKey, imVersion: NimCore.versionName);
if (kIsWeb) {
// Disable the browser context menu so package-level right-click menus work on Web.
await BrowserContextMenu.disableContextMenu();
}
setupLocator();
late NIMSDKOptions op;
if (options == null) {
final enableV2CloudConversation = await enableCloudConversation;
if (kIsWeb) {
options = NIMWebSDKOptions(
initializeOptions: NIMInitializeOptions(
appkey: appKey,
enableV2CloudConversation: enableV2CloudConversation,
apiVersion: 'v2',
debugLevel: 'debug',
),
appKey: appKey);
} else if (Platform.isAndroid) {
final directory = await getExternalStorageDirectory();
op = NIMAndroidSDKOptions(
appKey: appKey,
shouldSyncStickTopSessionInfos: true,
enableTeamMessageReadReceipt: true,
enableFcs: false,
enableV2CloudConversation: enableV2CloudConversation,
sdkRootDir: directory != null ? '${directory.path}/NIMFlutter' : null,
enablePreloadMessageAttachment: true,
);
} else if (Platform.isIOS) {
final directory = await getApplicationDocumentsDirectory();
op = NIMIOSSDKOptions(
appKey: appKey,
shouldSyncStickTopSessionInfos: true,
enableTeamMessageReadReceipt: true,
sdkRootDir: '${directory.path}/NIMFlutter',
apnsCername: 'ENTERPRISE',
pkCername: 'DEMO_PUSH_KIT',
enableV2CloudConversation: enableV2CloudConversation,
enablePreloadMessageAttachment: true,
);
} else if (Platform.isWindows || Platform.isMacOS) {
options = NIMPCSDKOptions(
basicOption: NIMBasicOption(
enableCloudConversation: enableV2CloudConversation,
reduceUnreadOnMessageRecall: true,
teamNotificationBadge: true,
),
appKey: appKey);
}
} else {
op = options;
}
var initResult = NimCore.instance.isInitialized;
if (!initResult) {
var nimInitResult = await NimCore.instance.initialize(op);
initResult = nimInitResult.isSuccess;
}
return initResult;
}