index.uts 679 B

123456789101112131415161718192021
  1. import { bundleManager, common } from '@kit.AbilityKit';
  2. import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'
  3. import { getAbilityContext } from '@dcloudio/uni-runtime'
  4. import { OpenSchema, CanOpenURL } from '../interface.uts'
  5. export const openSchema : OpenSchema = function (url : string) : void {
  6. (getAbilityContext() as common.UIAbilityContext)?.openLink(url, {
  7. appLinkingOnly: false
  8. } as OpenLinkOptions)
  9. }
  10. export const canOpenURL : CanOpenURL = function (url : string) : boolean {
  11. try {
  12. return bundleManager.canOpenLink(url)
  13. } catch (error) {
  14. console.error('[uts-openSchema] url param Error:', JSON.stringify(url))
  15. return false
  16. }
  17. }