简体   繁体   English

如何在Meteor角ios应用程序中打开外部链接?

[英]How to open an external link in a Meteor angular ios app?

I have a Meteor (v 1.2.0.2) angular mobile app and need to have a link to an external webpage but the links would not open on android or ios. 我有一个Meteor(v 1.2.0.2)角度移动应用程序,需要链接到外部网页,但是该链接在android或ios上无法打开。 After researching, I found from this question that I could add a cordova plugin called inAppBrowser 经过研究,我发现这个问题可以添加一个名为inAppBrowser的cordova插件。

How to get links to open in the native browser in iOS Meteor apps? 如何获取链接以在iOS Meteor应用程序的本机浏览器中打开?

I used this from one of the answers to add the inAppBrowser plugin 我使用了答案之一来添加inAppBrowser插件

meteor add cordova:cordova-plugin-inappbrowser@ https://github.com/apache/cordova-plugin-inappbrowser/tarball/bc9036d90a1f3f2220b5fc29b77cf2405e7fd781 流星添加cordova:cordova-plugin-inappbrowser @ https://github.com/apache/cordova-plugin-inappbrowser/tarball/bc9036d90a1f3f2220b5fc29b77cf2405e7fd781

After that my link worked on my android but not on my ipad. 之后,我的链接在我的android上有效,但在我的ipad上无效。

Here is my html 这是我的html

<a ng-click="adClick(pageAd.link, pageAd._id)">
    <img ng-src="/images/ads/{{pageAd.src}}" alt="{{pageAd.alt}}" />
</a>

and the function in my controller 和我控制器中的功能

$scope.adClick = function(url, adId)
{
  $meteor.call("incrementAdCount", adId).then(
    function(data){
      window.open(url, "_system");
    },

    function(error) {

    }

  );

}

On the ipad my ad count method works every time that I click, but the window.open does not seem to do anything. 在ipad上,每次点击我的广告计数方法都有效,但是window.open似乎没有任何作用。 On android it all works. 在android上一切正常。

Is there any additional setup I need to do for inAppBrowser in meteor for the ios link to work? 我需要为流星中的inAppBrowser做任何其他设置以使ios链接正常工作吗? I feel like it should be simple but after hours of searching I can find almost nothing on this for meteor, so maybe I'm looking in the wrong places. 我觉得它应该很简单,但是经过数小时的搜索,我几乎找不到关于流星的任何东西,所以也许我在错误的地方寻找。

I also tried using the angular $window.open, which also worked on android but not ios. 我也尝试使用有角的$ window.open,它也可以在android上使用,但不能在ios上使用。

I decided to research the cordova plugin since I was finding little to help when searching for meteor. 我决定研究cordova插件,因为搜索流星时几乎找不到帮助。 In the cordova inAppBrowser plugin readme I found this: 在cordova inAppBrowser插件自述文件中,我发现了这一点:

"If you want all page loads in your app to go through the InAppBrowser, you can simply hook window.open during initialization. For example:" “如果您希望应用程序中的所有页面加载都通过InAppBrowser进行,则只需在初始化期间挂接window.open 。例如:”

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
}

But anywhere I use the cordova variable in my meteor project, it is undefined. 但是在流星项目中我使用cordova变量的任何地方,它都是未定义的。 Is this even available in Meteor? 这甚至在流星中可用吗? And If I needed to do that why did it work in android without doing it? 如果我需要这样做,为什么不这样做就可以在android中工作呢?

My main question is what else do I need to do to open a link in a mobile ios app? 我的主要问题是在移动ios应用程序中打开链接还需要做什么?

I figured out the solution. 我想出了解决方案。 I started going through the cordova build folder (I figured I shouldn't need to change anything there but just to figure things out I looked around). 我开始浏览cordova build文件夹(我认为我不需要在此进行任何更改,而只是想环顾四周)。 I saw that there were 2 folders with my project name, but one was an old name I had for the project (I recently renamed it). 我看到有2个文件夹,其中包含我的项目名称,但其中一个是我在该项目中使用的旧名称(我最近对其进行了重命名)。

I realized that when I do a mobile build from meteor it does not delete any old files, just overwrites files that the new build generates. 我意识到,当我从流星进行移动构建时,它不会删除任何旧文件,而只是覆盖新构建生成的文件。 I had some folders and files in the build that were still there from previous builds. 我在构建中有一些文件夹和文件,这些文件夹和文件仍在以前的构建中。 So I deleted the entire mobile build instead of just overwriting it and rebuilt the project, and my ios link worked! 因此,我删除了整个移动版本,而不仅仅是覆盖它并重建了项目,并且我的ios链接起作用了!

It looks like xcode was using some of the old files when I built my project, and the old config didn't have the inAppBrowser so it didn't work. 似乎在我构建项目时xcode正在使用一些旧文件,并且旧配置没有inAppBrowser,因此它不起作用。

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

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