When testing updates with my fairly straightforward app on Xcode 7 and iOS 9 I’m having problems retrieving JSON feeds fairly regularly. For instance I’ll retrieve a JSON feed which I then output in a list. Pre iOS 9…no problem. Now I consistently get ERROR: Error Fetched Feed in the Xcode debug console. Both in the Simulator and when loaded to the device. However, I can refresh the page and the feed loads.
Here is the factory that I use to pull the JSON:
> WELSMobile.factory('GetJSONData', function ($http, $q) {
> return {
> getJSONFeed: function(link1) {
> var deferred = $q.defer();
> $http.get(link1)
> .success(function(data) {
> if (typeof data === 'object') {
> deferred.resolve(data);
> } else {
> deferred.reject(data);
> }
> }).error(function(data, status, headers, config) {
> deferred.reject(data);
> });
> return deferred.promise;
> }
> };
> });
Here is how I call it:
> WELSMobile.controller("ListRead", ["$scope", "GetJSONData", ListRead]);
> function ListRead($scope, GetJSONData) {
> var url = "";
> var theURL = window.location.hash;
> if (theURL.search("todaysdevotionlist") > 1) {
> url = TodaysDevotion;
> }
> if (theURL.search("3yrbiblelist") > 1) {
> url = ThreeYearBible;
> }
> if (theURL.search("militarydevotionlist") > 1) {
> url = MilitaryDevotion;
> }
> GetJSONData.getJSONFeed(url)
> .then(function (data) {
> $scope.feed = {
> items: data,
> title: data.title,
> length: data.length
> };
> }, function (error) {
> console.error('Error fetching feed:', error);
> });
> $scope.refresh = function () {
> location.reload();
> };
> }
Here is how the page/list get’s refreshed (which usually loads the content correctly:
> $scope.refresh = function () {
> location.reload();
> };