diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index 4bc6f8c3d9a386e5433e56f216562e809a7a52b1..05dd6c8f33fe42e5f1a7299e788b07e716f76aa6 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -95,9 +95,17 @@ switchInputMethod(target: InputmethodProperty, callback: AsyncCallback<boolea **示例:** ```js - inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => { - prompt.showToast({message:"切换输入法成功" + this.imeList[this.flag].packageName, duration: 200}); - }); +inputmethod.switchInputMethod({packageName:"com.example.kikakeyboard", methodId:"com.example.kikakeyboard"} ,(err,result) => { + if (err == undefined) { + console.info("switchInputMethod callback result---err: " + err.msg); + return; + } + if (result) { + console.info("Success to switchInputMethod.(callback)"); + } else { + console.info("Failed to switchInputMethod.(callback)"); + } +}); ``` ## inputMethod.switchInputMethod9+ switchInputMethod(target: InputmethodProperty): Promise<boolean> @@ -121,9 +129,18 @@ switchInputMethod(target: InputmethodProperty): Promise<boolean> ```js - inputMethod.switchInputMethod({packageName:"com.ohos.inputApp", methodId:"InputDemoService"}).then(res => { - prompt.showToast({message:"切换输入法成功" + this.imeList[this.flag].packageName, duration: 200}); - }); +async function InputMethod() { + await inputMethod.switchInputMethod({packageName:"com.example.kikakeyboard", + methodId:"com.example.kikakeyboard"}).then((result) => { + if (result) { + console.info("Success to switchInputMethod.(promise)"); + } else { + console.info("Failed to switchInputMethod.(promise)"); + } + }).catch((err) => { + console.info("switchInputMethod promise err: " + err.msg); + }); +} ``` ## InputMethodController