performFetchWithCompletionHandler not being called into production

0

I'm implementing an app in Swift 2 that makes requests to an xml feed from time to time, and triggers a local notification. For that, I'm using the performFetchWithCompletionHandler method in AppDelegate. Locally, using my device, the method is called normally. But already in production, testing via Testflight, it is never called ... Do I need to implement something so it triggers production? What happens in this case that my beta testers do not receive automatic notifications?

PS: I'm using Parse.com, and when I send manual notifications, they get

    
asked by anonymous 09.10.2015 / 23:54

1 answer

2

The problem has been circumvented, now using Push Notifications instead of Local Notifications. Parse.com itself offers a feature called Cloud Code, where you can write a task to read the feed from time to time and trigger push notifications. Here is the commented code below:

Remembering that the code is done in Javascript by referencing the XMLReader libraries and SAX

var xmlreader = require('cloud/xmlreader.js');

var url = "http://www.zelda.com.br/rss.xml";

function SavePost(title, link){
    var PostClass = Parse.Object.extend("Post");
    var post = new PostClass();
    post.set("title", title);
    post.set("link", link);
    post.save();
}

function SendPush(title, link){
    var query = new Parse.Query(Parse.Installation);
    Parse.Push.send({
        where: query,
        data: {
            url: link,
            alert: title,
            sound: "default"
        }
        }, {
            success: function() {
                SavePost(title, link);
            },
            error: function(error) {
            console.log("Error sending push: " + error);
        }
    });
}

Parse.Cloud.job("fetchPosts", function(request, response) {
    Parse.Cloud.httpRequest({
        url: url,
        success: function(httpResponse) {
            var responseText = httpResponse.text;

            xmlreader.read(responseText, function (err, res){
                var newPost = res.rss.channel.item;

                var title = newPost.array[0].title.text();
                var link = newPost.array[0].link.text();

                var PostClass = Parse.Object.extend("Post");
                var query = new Parse.Query(PostClass);
                query.equalTo("link", link);
                query.find({
                    success: function(results) {
                        if (results.length == 0){
                            SendPush(title, link);
                        } else {
                            response.error("Post already pushed");
                        }
                    }
                });
            });
        },
        error: function(httpResponse) {
            console.error('Request failed with response code ' + httpResponse.status);
            response.error("Error fetching posts from feed");
        }
    });
});
    
13.10.2015 / 14:10