1e41f4b71Sopenharmony_ci# ability子系统Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## cl.ability.1 createModuleContext接口废弃 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**访问级别** 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci公开接口。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**废弃原因** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci使用该接口创建的context无法正确获取资源。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**废弃影响** 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci该变更为兼容性变更,提供了新接口。 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci**起始 API Level** 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci9 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**废弃发生版本** 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci从OpenHarmony SDK 5.0.0.37开始。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**废弃的接口/组件** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci|接口声明|废弃说明|替代接口| 28e41f4b71Sopenharmony_ci|-------|-------|-------| 29e41f4b71Sopenharmony_ci|createModuleContext(moduleName: string): Context|用这个接口创建的context无法正确获取资源,建议使用替代接口。|createModuleContext(context: Context, moduleName: string): Promise<Context>| 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**适配指导** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci需要使用新的替代接口,替代接口为带context入参的createModuleContext。 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci废弃前代码示例: 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci```ts 38e41f4b71Sopenharmony_ciimport { common, UIAbility } from '@kit.AbilityKit'; 39e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 42e41f4b71Sopenharmony_ci onCreate() { 43e41f4b71Sopenharmony_ci console.log('MyAbility onCreate'); 44e41f4b71Sopenharmony_ci let moduleContext: common.Context; 45e41f4b71Sopenharmony_ci try { 46e41f4b71Sopenharmony_ci moduleContext = this.context.createModuleContext('entry'); 47e41f4b71Sopenharmony_ci } catch (error) { 48e41f4b71Sopenharmony_ci console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 49e41f4b71Sopenharmony_ci } 50e41f4b71Sopenharmony_ci } 51e41f4b71Sopenharmony_ci} 52e41f4b71Sopenharmony_ci``` 53e41f4b71Sopenharmony_ci废弃后代码示例: 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci```ts 56e41f4b71Sopenharmony_ciimport { common, UIAbility } from '@kit.AbilityKit'; 57e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 60e41f4b71Sopenharmony_ci onCreate() { 61e41f4b71Sopenharmony_ci console.log('MyAbility onCreate'); 62e41f4b71Sopenharmony_ci let moduleContext: common.Context; 63e41f4b71Sopenharmony_ci try { 64e41f4b71Sopenharmony_ci common.createModuleContext(this.context,'entry').then((data: Context)=>{ 65e41f4b71Sopenharmony_ci moduleContext = data; 66e41f4b71Sopenharmony_ci }).catch((err : BusinessError)=>{ 67e41f4b71Sopenharmony_ci console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 68e41f4b71Sopenharmony_ci }) 69e41f4b71Sopenharmony_ci } catch (error) { 70e41f4b71Sopenharmony_ci console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 71e41f4b71Sopenharmony_ci } 72e41f4b71Sopenharmony_ci } 73e41f4b71Sopenharmony_ci} 74e41f4b71Sopenharmony_ci``` 75e41f4b71Sopenharmony_ci## cl.ability.2 createModuleContext接口废弃 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**访问级别** 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci系统接口。 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**废弃原因** 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci使用该接口创建的context无法正确获取资源。 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**废弃影响** 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci该变更为兼容性变更,提供了新接口。 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**起始 API Level** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci9 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**废弃发生版本** 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci从OpenHarmony SDK 5.0.0.37开始。 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**废弃的接口/组件** 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci|接口声明|废弃说明|替代接口| 100e41f4b71Sopenharmony_ci|-------|-------|-------| 101e41f4b71Sopenharmony_ci|createModuleContext(bundleName: string, moduleName: string): Context|用这个接口创建的context无法正确获取资源,建议使用替代接口。|createModuleContext(context: Context, bundleName: string, moduleName: string): Promise<Context>| 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**适配指导** 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci需要使用新的替代接口,替代接口为带context入参的createModuleContext。 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci废弃前代码示例: 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci```ts 110e41f4b71Sopenharmony_ciimport { common, UIAbility } from '@kit.AbilityKit'; 111e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 114e41f4b71Sopenharmony_ci onCreate() { 115e41f4b71Sopenharmony_ci console.log('MyAbility onCreate'); 116e41f4b71Sopenharmony_ci let moduleContext: common.Context; 117e41f4b71Sopenharmony_ci try { 118e41f4b71Sopenharmony_ci moduleContext = this.context.createModuleContext('bunlename', 'entry'); 119e41f4b71Sopenharmony_ci } catch (error) { 120e41f4b71Sopenharmony_ci console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 121e41f4b71Sopenharmony_ci } 122e41f4b71Sopenharmony_ci } 123e41f4b71Sopenharmony_ci} 124e41f4b71Sopenharmony_ci``` 125e41f4b71Sopenharmony_ci废弃后代码示例: 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci```ts 128e41f4b71Sopenharmony_ciimport { common, UIAbility } from '@kit.AbilityKit'; 129e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 132e41f4b71Sopenharmony_ci onCreate() { 133e41f4b71Sopenharmony_ci console.log('MyAbility onCreate'); 134e41f4b71Sopenharmony_ci let moduleContext: common.Context; 135e41f4b71Sopenharmony_ci try { 136e41f4b71Sopenharmony_ci common.createModuleContext(this.context, 'bunlename', 'entry').then((data: Context)=>{ 137e41f4b71Sopenharmony_ci moduleContext = data; 138e41f4b71Sopenharmony_ci }).catch((err : BusinessError)=>{ 139e41f4b71Sopenharmony_ci console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 140e41f4b71Sopenharmony_ci }) 141e41f4b71Sopenharmony_ci } catch (error) { 142e41f4b71Sopenharmony_ci console.error(`createModuleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 143e41f4b71Sopenharmony_ci } 144e41f4b71Sopenharmony_ci } 145e41f4b71Sopenharmony_ci} 146e41f4b71Sopenharmony_ci``` 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci## cl.ability.3 createBundleContext接口废弃 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**访问级别** 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci系统接口。 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**废弃原因** 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci使用该接口创建的context无法正确获取资源。 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci**废弃影响** 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci该变更为兼容性变更,提供了新接口。 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**起始 API Level** 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci9 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**废弃发生版本** 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci从OpenHarmony SDK 5.0.0.37开始。 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**废弃的接口/组件** 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci|接口声明|废弃说明|替代接口| 173e41f4b71Sopenharmony_ci|-------|-------|-------| 174e41f4b71Sopenharmony_ci|createBundleContext(bundleName: string): Context|用这个接口创建的context无法正确获取资源,建议使用替代接口。|createBundleContext(context: Context, bundleName: string): Promise<Context>| 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**适配指导** 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci需要使用新的替代接口,替代接口为带context入参的createBundleContext。 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci废弃前代码示例: 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci```ts 183e41f4b71Sopenharmony_ciimport { common, UIAbility } from '@kit.AbilityKit'; 184e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 187e41f4b71Sopenharmony_ci onCreate() { 188e41f4b71Sopenharmony_ci console.log('MyAbility onCreate'); 189e41f4b71Sopenharmony_ci let bundleContext: common.Context; 190e41f4b71Sopenharmony_ci try { 191e41f4b71Sopenharmony_ci bundleContext = this.context.createBundleContext('bundlename'); 192e41f4b71Sopenharmony_ci } catch (error) { 193e41f4b71Sopenharmony_ci console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 194e41f4b71Sopenharmony_ci } 195e41f4b71Sopenharmony_ci } 196e41f4b71Sopenharmony_ci} 197e41f4b71Sopenharmony_ci``` 198e41f4b71Sopenharmony_ci废弃后代码示例: 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci```ts 201e41f4b71Sopenharmony_ciimport { common, UIAbility } from '@kit.AbilityKit'; 202e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 205e41f4b71Sopenharmony_ci onCreate() { 206e41f4b71Sopenharmony_ci console.log('MyAbility onCreate'); 207e41f4b71Sopenharmony_ci let bundleContext: common.Context; 208e41f4b71Sopenharmony_ci try { 209e41f4b71Sopenharmony_ci common.createBundleContext(this.context,'bundlename').then((data: Context)=>{ 210e41f4b71Sopenharmony_ci bundleContext = data; 211e41f4b71Sopenharmony_ci }).catch((err : BusinessError)=>{ 212e41f4b71Sopenharmony_ci console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 213e41f4b71Sopenharmony_ci }) 214e41f4b71Sopenharmony_ci } catch (error) { 215e41f4b71Sopenharmony_ci console.error(`createBundleContext failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); 216e41f4b71Sopenharmony_ci } 217e41f4b71Sopenharmony_ci } 218e41f4b71Sopenharmony_ci} 219e41f4b71Sopenharmony_ci```