简体   繁体   English

带有 .net 核心后端的 Ionic 使用电容器到 android 应用程序

[英]Ionic with .net core backend to android app using capacitor

I am new to Ionic and in fact new to building apps altogether.我是 Ionic 的新手,实际上是完全构建应用程序的新手。
So far I have built an app successfully.到目前为止,我已经成功构建了一个应用程序。 This is what I have done so far:这是我到目前为止所做的:

Following Ionic docs, I built it using Ionic build --prod and saved the build in wwwroot folder inside Api.按照 Ionic 文档,我使用 Ionic build --prod 构建它并将构建保存在 Api 内的 wwwroot 文件夹中。 Publishes using dotnet release.使用 dotnet release 发布。 Then uploaded to a hosted server.然后上传到托管服务器。 It's running fine on the web.它在网络上运行良好。
Now, I have used the following to convert the project to android app.现在,我使用以下内容将项目转换为 android 应用程序。
1. Ran ionic capacitor add android 1.冉离子电容添加android
2. Ionic cap copy android 2.离子帽复制android
3. Ionic cap open android 3. 离子帽开安卓
This opens the android studio and it is built correctly.这将打开 android studio 并正确构建。
When I debug the app in android studio the home page loads fine (it is a static page which doesn't make api call).当我在 android studio 中调试应用程序时,主页加载正常(它是一个不进行 api 调用的静态页面)。
What is especially bugging me is that the debug window shows its running on localhost, whereas I have used the url of the hosted server.特别困扰我的是调试窗口显示它在本地主机上运行,​​而我使用了托管服务器的 url。 When I click on any links, they too, again, point to localhost.当我单击任何链接时,它们也会再次指向 localhost。 I have also added我也添加了
"proxies": “代理”:

  [ <br/>
    {<br/>
      "path": "/api/",<br/>
      "proxyUrl": "http://apiurl.com"<br/>
    }<br/>
  ] <br/>

in config.json在 config.json 中
I am sure I am missing a point.我确定我遗漏了一点。 Can some enlightened being point me towards right direction?一些开明的人能指出我正确的方向吗? Thanks!谢谢!

I got around it eventually.我最终解决了它。 For anyone else facing similar situation, this is what we need to do.对于其他面临类似情况的人,这就是我们需要做的。 In capacitor.config.json file we need to specify 'server' from where we are getting the Api data.在capacitor.config.json 文件中,我们需要指定'server' 从中获取Api 数据的位置。

"appName": "Your Site",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"cordova": {},

//This part mentioned below is important.
"server": {
  "url": "https://yoursite.com",
  "allowNavigation": ["yoursite.com", "*.yoursite.com"]
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM