login method
Future<NEResult>
login(
- String appKey,
- String accountId,
- String token, {
- NECertificateConfig? certificateConfig,
- NEExtraConfig? extraConfig,
Implementation
Future<NEResult> login(String appKey, String accountId, String token,
{NECertificateConfig? certificateConfig,
NEExtraConfig? extraConfig}) async {
CallKitUILog.i(_tag,
'CallManager login(appKey:$appKey, accountId:$accountId, certificateConfig:$certificateConfig, extraConfig:$extraConfig) version:${Constants.pluginVersion}');
// 保存 appKey 和 extraConfig
_appKey = appKey;
_extraConfig = extraConfig ?? NEExtraConfig(); // 默认生成一个配置
CallKitUILog.i(_tag,
'CallManager login: appKey saved = $_appKey, extraConfig = $_extraConfig');
late NIMSDKOptions options;
if (Platform.isAndroid) {
options = NIMAndroidSDKOptions(
appKey: appKey,
);
//若需要使用云端会话,请提前开启云端会话
//enableV2CloudConversation: true,
} else if (Platform.isIOS) {
options = NIMIOSSDKOptions(
appKey: appKey,
//若需要使用云端会话,请提前开启云端会话
//enableV2CloudConversation: true,
apnsCername: certificateConfig?.apnsCername,
pkCername: certificateConfig?.pkCername,
);
}
var initRet = await NimCore.instance.initialize(options);
if (initRet.code == 0) {
NEEventNotify().notify(imSDKInitSuccessEvent, {});
}
NEResult result = NEResult(code: 0, message: 'success');
var imRet = await NimCore.instance.loginService.login(
accountId,
token,
NIMLoginOption(),
);
if (imRet.code == 0) {
NEEventNotify()
.notify(loginSuccessEvent, {'accountId': accountId, 'token': token});
}
result = NEResult(code: imRet.code, message: imRet.errorDetails);
return result;
}