harmony 鸿蒙主题框架changeLog
主题框架changeLog
cl.theme.1 API9接口支持异常处理
下列模块内部接口使用业务逻辑返回值表示错误信息,不符合OpenHarmony接口错误码规范。在API9进行变更。 - 壁纸管理服务:@ohos.wallpaper.d.ts
- 锁屏管理服务:@ohos.screenLock.d.ts
以上模块中的接口变更为: 同步接口:通过抛出异常的方式返回错误信息。 异步接口:参数检查错误同步抛出,业务逻辑错误通过AsyncCallback或Promise的error对象抛出。
变更影响
基于此前版本开发的应用,需适配接口的错误信息返回方式,否则会影响原有业务逻辑。
关键接口/组件变更
以下标记为壁纸管理服务接口废除:
   - getColors(wallpaperType: WallpaperType, callback: AsyncCallback
壁纸管理服务替代接口如下:
   - getColorsSync(wallpaperType: WallpaperType): Array
以下标记为壁纸管理服务接口变更:
   - on(type: ‘colorChange’, callback: (colors: Array
以下标记为锁屏管理服务接口废除:
   - isScreenLocked(callback: AsyncCallback
锁屏管理服务替代接口如下:
   - isLocked(): boolean;
   - isSecure(): boolean;
   - unlock(callback: AsyncCallback
以下标记为锁屏管理服务接口删除:
   - lockScreen(callback: AsyncCallback
以下标记为锁屏管理服务接口新增:
   - lock(callback: AsyncCallback
以下标记为锁屏管理服务接口变更:
   - onSystemEvent(callback: Callback
壁纸管理服务适配指导
异步接口以getImage为例,示例代码如下:
import pointer from '@ohos.wallpaper';
try {
    wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
        console.log(`success to getImage: ${JSON.stringify(data)}`);
    }).catch((error) => {
        console.error(`failed to getImage because: ${JSON.stringify(error)}`);
    });
} catch (err) {
    console.error(`failed to getImage because: ${JSON.stringify(err)}`);
}
同步接口以getFileSync为例,示例代码如下:
import pointer from '@ohos.wallpaper';
try {
    let file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
} catch (err) {
    console.error(`failed to getFileSync because: ${err.message}`);
}
锁屏管理服务适配指导
异步接口以lock为例,示例代码如下:
import screenLock from '@ohos.screenlock';
try {
  screenLock.lock((err, data) => {      
    if (err) {
        console.error(`Failed to lock the screen, because: ${err.message}`);
        return;    
    }
    console.info(`lock the screen successfully. result: ${data}`);
  });
} catch (err) {
    console.error(`Failed to lock the screen, because: ${err.message}`);
}
同步接口以onSystemEvent为例,示例代码如下:
import screenLock from '@ohos.screenlock';
try {
   let isSuccess = screenLock.onSystemEvent((event) => {
       console.log(`Register the system event which related to screenlock successfully. eventType: ${event.eventType}`)
   });
} catch (err) {
   console.error(`Failed to register the system event which related to screenlock, because: ${err.message}`)
}
你可能感兴趣的鸿蒙文章
- 所属分类: 后端技术
- 本文标签:
热门推荐
- 
                        2、 - 优质文章
- 
                        3、 gate.io
- 
                        8、 openharmony
- 
                        9、 golang