$http.get doesn't work when live-testing on iOS


My app works great on Android and in the browser, but on my iPhone 4s running iOS 9.2.1, my initial $http.get doesn’t complete, nor does it throw an error.

I’ve read about needing to install the whitelist plugin, which I did. I also installed an npm package (https://www.npmjs.com/package/cordova-plugin-transport-security) which added the required lines into AppName-info.plist just fine, but no matter what I do, my $http.get simply won’t run, even though the website in question is https.

Full disclosure: Tonight is the second time I’ve ever touched Xcode, my first time being about five years prior to fiddle with Objective-C

Here’s the code in question that doesn’t run:

.factory('aceFactory', ["$http", "$q", function($http, $q, $rootScope) {
  return {
    service: "https://api.example.com/v1/?type=all",
    loadData: function(lat, long) {
      var deferred = $q.defer()
      $http.get(this.service + "&source=app&lat=" + lat + "&long=" + long + "&tz=" + new Date().getTimezoneOffset(), {
        timeout: 15000
      }).then(function(data) {
      }, function(err) {
      return deferred.promise

The code code doesn’t even time out after 15 seconds, it just sits there with the spinner (that is shown before the $http.get call) and never progresses, even after half an hour of waiting.

Anyone come across this issue yet?



So my plist file is fine (contains the same lines as what is shown in the gist you posted), but my $http.get still won’t complete.


Right, so I’ve made some progress on this. I discovered that if I manually call the function that does the $http.get call (it currently runs $ionicPlatform.ready), then my app actually does load. The $http.get call simply wasn’t firing on ready(), but runs just fine when I run it myself

For reference, I set Mobile Safari to allow remote debugging, then went into Safari, turned on developer mode, then opened the web inspector for the iPhone, on my Mac. Then I manually ran: angular.element($0).scope().loadData() which actually tried to load my data, then succeeded

But any explanations as to why I have to do that and why $ionicPlatform.ready doesn’t work as expected, would be greatly appreciated.


After hours of fiddling, working with remote debugging in Safari and tons of console.log calls, plus barking up several wrong trees, I figured out that my geolocation calls were failing and not raising an error. I installed the cordova geolocation plugin (instead of using the browser implementation) and immediately got asked if I wanted to allow the app to use my location.

Now my data loads perfectly every time.