performFetchWithCompletionHandler not being called into production

Asked

Viewed 19 times

0

I’m implementing a Swift 2 app that requests an xml feed from time to time, and triggers a local notification. For that, I’m using the method performFetchWithCompletionHandler no 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 for it to fire in production? What happens if my beta testers do not receive automatic notifications?

PS: I am using Parse.com, and when I send manual notifications, they receive

  • The requests from time to time would be around how long? Is the app in a finished state? If possible put the code in which you perform these questions

  • @Gian, time would be as little as possible... I really appreciate the help, but since I needed something faster, I found a way to solve this problem using Push Notifications with Parse.com even... I will post the code explaining how I did, to leave future information :)

1 answer

2


The problem has been solved by 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 fire push Notifications. Follow the code commented below:

Remembering that the code is made in Javascript, referencing libraries Xmlreader 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");
        }
    });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.