【发布时间】:2022-10-25 17:46:48
【问题描述】:
请帮助它已经有一段时间了,我无法解决这个问题。
我们正在使用Vuejs和Capacitorjs v4构建一个移动应用程序。
为了获取用户的位置,我们使用了来自 Capacitorjs 官方文档的@capacitor/geolocation 插件,链接:https://capacitorjs.com/docs/apis/geolocation。
当我在本地主机上本地测试它时它工作正常。但是,当我将 web 视图链接更改为生产而不是 localhost 时,我收到此错误:Uncaught (in promise) Error: "Geolocation" plugin is not implemented on android,即使它已成功注册,因为我可以在 android studio 中看到日志:
日志:
D/EgretLoader: The context is not activity
D/Capacitor: Starting BridgeActivity
D/Capacitor: Registering plugin: WebView
D/Capacitor: Registering plugin: AppLauncher
D/Capacitor: Registering plugin: Geolocation
D/Capacitor: Registering plugin: Preferences
D/Capacitor: Registering plugin: PushNotifications
D/Capacitor: Registering plugin: SplashScreen
代码:
if(Capacitor.getPlatform() != "web"){
const coordinates = await Geolocation.getCurrentPosition();
finalResult = Object.assign(stringObject,{"time" : nd},{"longitude" : coordinates.coords.longitude.toString(), "latitude": coordinates.coords.latitude.toString()});
}
MainAccticity.java
public class MainActivity extends BridgeActivity {}
笔记:
我尝试了所有在线解决方案(没有一个有效),例如:
- MainActivity.java 文件中插件的手动注册
- build.gradle 文件中的 minifyEnabled false
请帮助它已经有两个星期了,我们仍然被困在这个问题上。 谢谢,感谢您的帮助。
更新: 配置文件:
{
"appId": "com.example.is.app",
"appName": "App Name",
"webDir": "dist",
"bundledWebRuntime": false,
"plugins": {
"SplashScreen": {
"launchShowDuration": 4000,
"launchAutoHide": true,
"fadeOutDuration": 1000,
"splashFullScreen": false,
"splashImmersive": false
},
},
"cordova": {},
"server": {
"cleartext": true,
"hostname": "hemera-is-dev",
//"url": "https://www.myremotewebsite.com/app/dist/",(not working even though other plugins work normally on the remote website)
"url": "http://localhost/app/dist/",
"allowNavigation": [
"*"
]
}
}
【问题讨论】:
-
“当我将网络视图链接更改为生产而不是本地主机时”是什么意思?
-
在电容器配置文件中,我有一个服务器{},其中包含主机名、URL、明文等。当我将 URL 从本地主机更改为远程主机时,插件会返回此错误。我更新了问题,以便您可以看到包含设置的文件。
标签: android vue.js vuejs3 capacitor capacitor-plugin