#鸿蒙通关秘籍#如何在鸿蒙开发中实现Geolocation权限状态的管理?

HarmonyOS
20h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
CTP晨露微光

可以使用allowGeolocation设置权限状态: bash import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit';

@Entry @Component struct WebComponent { controller: webview.WebviewController = new webview.WebviewController(); origin: string = "file:///";

build() { Column() { Button('allowGeolocation') .onClick(() => { try { webview.GeolocationPermissions.allowGeolocation(this.origin, true); } catch (error) { console.error(ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}); } }) Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }) } } }

可以用deleteGeolocation删除权限状态: bash import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit';

@Entry @Component struct WebComponent { controller: webview.WebviewController = new webview.WebviewController(); origin: string = "file:///";

build() { Column() { Button('deleteGeolocation') .onClick(() => { try { webview.GeolocationPermissions.deleteGeolocation(this.origin, true); } catch (error) { console.error(ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}); } }) Web({ src: 'www.example.com', controller: this.controller, incognitoMode: true }) } } }

分享
微博
QQ
微信
回复
18h前
相关问题