Initialization
Update time: 2022/09/02 03:19:33
Before enabling SDK features, you must call NIM.ClientAPI.Init
function for initialization. The function is declared using the following code.
csharppublic static bool Init(string appDataDir, string appInstallDir = "", NimUtility.NimConfig config = null)
- appDataDir: The data cache directory must have read-write permission. All SDK data is stored in the directory.
- appInstallDir: Installation directory for program, unavailable temporarily
- config: SDK configuration. Some behaviors of SDK can be customized by setting the parameter. It is not required to update default setting, and
null
shall be retained.
The login can be executed only when the function is executed successfully and returns true
.
Data Cache Directory
The data cache directory can use independent directory name or complete path. SDK will automatically generate the directory. The directory name can be found under Windows, and the final directory is located in the directory C:\Users\XXX\AppData\Local of current user. We recommend that you use the full path to view the data on Android and iOS platforms.
Settings for Unity demo AppData directory:
csharppublic static string AppDataPath
{
get
{
if (string.IsNullOrEmpty(_appDataPath))
{
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
_appDataPath = Application.persistentDataPath + "/NimUnityDemo";
}
else if (Application.platform == RuntimePlatform.Android)
{
string androidPathName = "com.netease.nim_unity_android_demo";
if (System.IO.Directory.Exists("/sdcard"))
_appDataPath = Path.Combine("/sdcard", androidPathName);
else
_appDataPath = Path.Combine(Application.persistentDataPath, androidPathName);
}
else if (Application.platform == RuntimePlatform.WindowsEditor ||
Application.platform == RuntimePlatform.WindowsPlayer)
{
_appDataPath = "NimUnityDemo";
}
Debug.Log("AppDataPath:" + _appDataPath);
}
return _appDataPath;
}
}
- Installation directory for appInstallDir program, unavailable temporarily
- config SDK configuration. Some behaviors of SDK can be customized by setting the parameter. It is not required to update default behavior, and
null
shall be retained.
Description for the Parameter NimConfig
SDK General Configuration Options
SDKCommonSetting
includes SDK general configuration options as follows:
Parameter | Description |
---|---|
DataBaseEncryptKey | Database key, local cache data of encrypted users. Now, it only supports the encryption key with max. 32 characters. 32 characters are recommended |
PredownloadAttachmentThumbnail | It determines to preload thumbnail of attachment. The value is true by default. |
PreloadImageQuality | Preloaded image quality, with range 0 to 100. |
PreloadImageResize | Resizing the pre-loaded image, optional. For example 100x50 means width x height. |
LogLevel | It configures SDK log level. The higher the level is, the more detailed the log will be. The default level of SDK is Pro . |
CustomTimeout | It configures timeout duration for login (unit: s). The value is 30s by default. |
MaxLoginRetry | Maximum retry frequency at the time of failed login due to network |
SyncSessionAck | Set whether to sync the read and unread status with mulitiple terminals, true by default. |
NotNeedSaveCustomMsg | Set whether custom (kNIMMessageTypeCustom ) messages do not need to be saved, false by default. |
UsePriviteServer | Whether to use private server, false by default. |
Configurations of Private Server
SDKPrivateServerSetting
provides configuration options required for using private server. The option shall not be configured when CommsEase public server is used, with parameter description as follows:
Parameter | Description |
---|---|
LbsAddress | Server LBS address |
NOSLbsAddress | Private NOS LBS address |
LinkServerList | List of default CommsEase Link server addresses |
UploadServerList | List of default NOS server addresses |
DownloadServerList | List of default NOS download server addresses |
AccessServerList | Default NOS Access server address |
RSAPublicKey | RSA public key |
RsaVersion | RSA key version |
SDK Cleanup
When exiting the program, you shall invoke Cleanup
to clear up SDK released resources. Cleanup
shall be combined with Init
.