中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
Stage模型下如何获取键值型数据库的KVManager实例?
微信扫码分享
// 导入模块 import distributedKVStore from '@ohos.data.distributedKVStore'; let kvManager: distributedKVStore.KVManager | undefined = undefined; onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { let context = this.context; const kvManagerConfig: distributedKVStore.KVManagerConfig = { context: context, bundleName: 'com.example.datamanagertest' }; try { // 创建KVManager实例 kvManager = distributedKVStore.createKVManager(kvManagerConfig); console.info('Succeeded in creating KVManager.'); // 继续创建获取数据库 } catch (e) { let error = e as BusinessError; console.error(`Failed to create KVManager. Code:${error.code},message:${error.message}`); } if (kvManager !== undefined) { kvManager = kvManager as distributedKVStore.KVManager; //进行后续操作 //... } }