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

572 views Asked by At

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. After researching, I found from this question that I could add a cordova plugin called inAppBrowser

How to get links to open in the native browser in iOS Meteor apps?

I used this from one of the answers to add the inAppBrowser plugin

meteor add 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.

Here is my 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. On android it all works.

Is there any additional setup I need to do for inAppBrowser in meteor for the ios link to work? 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.

I decided to research the cordova plugin since I was finding little to help when searching for meteor. In the cordova inAppBrowser plugin readme I found this:

"If you want all page loads in your app to go through the InAppBrowser, you can simply hook window.open during initialization. For example:"

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. Is this even available in Meteor? And If I needed to do that why did it work in android without doing it?

My main question is what else do I need to do to open a link in a mobile ios app?

1

There are 1 answers

0
pope12 On

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). 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).

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!

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.