[英][Cordova][Android] Sockets not connecting when running on release build
但是,当我从商店运行发布版本时,应用程序不会连接到套接字。
我正在将 LaravelEcho 与 SocketIo 客户端一起使用。
搜索问题后,我发现了一些有关权限的结果,但我已经有了。
<uses-permission android:name="android.permission.INTERNET" />
是否可以在发布模式下调试应用程序?
这就是我导入 NgxLaravelEchoModule 的方式
NgxLaravelEchoModule.forRoot({ userModel: 'App.Models.User', notificationNamespace: 'App\\\\Notifications', options: { broadcaster: 'socket.io', host: environment.socketsURL } }),
我设法找出了套接字模块抛出的错误消息
xhr poll error
我花了几个小时寻找这个问题的答案(我知道这篇文章很旧,但也许它可以帮助某人)。 没有人能回答这个问题。 不过,我相信真正的答案是,默认情况下,Android 不喜欢 http。 相反,解决方案是在您的 socket.io 客户端上使用 https。 但设置起来很烦人。
更好的解决方案是在 Android 应用程序上允许 http。 在您的 AndroidManifest.xml 中,找到“应用程序”。 默认情况下它应该是这样的:
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
将android:usesCleartextTraffic="true"
附加到此以获得以下内容:
<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
编译您的 apk 并在 Android 设备上运行它。 瞧! 您现在可以连接到发布版本上的套接字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.