Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending Push Notifications as "Increment" badge is sent as "Undefined" to APNS #897

Closed
taufiq-husain opened this issue Mar 7, 2016 · 19 comments

Comments

@taufiq-husain
Copy link

Even though the Parse Push Notification support has been added as referenced here: #740 and here: #723. I've updated my Parse servers and updated my push notification cloud code (Javascript) but I'm still getting no increment on push notifications. I've traced the logs and it shows this:

2016-03-07T19:29:49.393797+00:00 app[web.1]: APNS Connection 0 Connected
2016-03-07T19:29:49.542413+00:00 app[web.1]: APNS Notification caused error: 8 for device  Device {
2016-03-07T19:29:49.521573+00:00 app[web.1]: APNS Connection 0 Notification transmitted to 3d8591f34b26c9bc3ba49cea14f6512224ab4201c9a4481092f6c1991e7b6a1f
2016-03-07T19:29:49.542428+00:00 app[web.1]:   connIndex: 0,
2016-03-07T19:29:49.542426+00:00 app[web.1]:   token: <Buffer 3d 85 91 f3 4b 26 c9 bc 3b a4 9c ea 14 f6 51 22 24 ab 42 01 c9 a4 48 10 92 f6 c1 99 1e 7b 6a 1f>,
2016-03-07T19:29:49.542429+00:00 app[web.1]:   appIdentifier: 'com.polarhills.LOL' } { encoding: 'utf8',
2016-03-07T19:29:49.542430+00:00 app[web.1]:    { aps: 
2016-03-07T19:29:49.542429+00:00 app[web.1]:   payload: 
2016-03-07T19:29:49.542431+00:00 app[web.1]:       { badge: undefined,
2016-03-07T19:29:49.542432+00:00 app[web.1]:         sound: undefined,
2016-03-07T19:29:49.542432+00:00 app[web.1]:         alert: 'Message from Taufiq Husain 😋',
2016-03-07T19:29:49.542433+00:00 app[web.1]:         'url-args': undefined,
2016-03-07T19:29:49.542434+00:00 app[web.1]:         category: undefined } },
2016-03-07T19:29:49.542434+00:00 app[web.1]:   expiry: undefined,
2016-03-07T19:29:49.542435+00:00 app[web.1]:   priority: 10,
2016-03-07T19:29:49.542436+00:00 app[web.1]:   retryLimit: -1,
2016-03-07T19:29:49.542436+00:00 app[web.1]:   device: undefined,
2016-03-07T19:29:49.542437+00:00 app[web.1]:   compiled: '{"aps":{"alert":"Message from Taufiq Husain 😋"}}',
2016-03-07T19:29:49.542438+00:00 app[web.1]:   truncateAtWordEnd: false,
2016-03-07T19:29:49.542439+00:00 app[web.1]:   _alert: 'Message from Taufiq Husain 😋' }
2016-03-07T19:29:49.544230+00:00 app[web.1]: APNS Connection 0 Disconnected
2016-03-07T19:29:49.612543+00:00 app[web.1]: APNS Connection 1 Connected
2016-03-07T19:29:49.613481+00:00 app[web.1]: APNS Connection 0 Connected
2016-03-07T19:29:49.551290+00:00 heroku[router]: at=info method=POST path="/parse/classes/_User" host=getlolapp.herokuapp.com request_id=f0847c95-4ed8-4022-9206-4b223c390a92 fwd="24.5.10.195" dyno=web.1 connect=1ms service=73ms status=200 bytes=95467

The issue maybe that the badge is not converted from Integer to String or something. Whenever I change my cloud code to badge: 1, it starts to work.

Here is my cloud code:

// Push Notifications
Parse.Cloud.define("send_push", function(request, response) {
    var query = new Parse.Query(Parse.User, {useMasterKey:true});
    query.containedIn("username", request.params.receivers);
    query.equalTo("enabled", true);
    Parse.Push.send({
        where: query,
        data: {
            alert: request.params.message,
            badge: "Increment" // 1 // request.params.badge
        }
    }, 
    { 
        useMasterKey: true 
    }, 
    {
        success: function() {
            response.success("Push notification sent!");
        },
        error: function(e) {
            response.error("Push notification error! Code: " + e.code + ", Message: " + e.message);
        }
    });
});

Any ideas on how I can fix this issue?

@flovilmart
Copy link
Contributor

and you don't see the badge property set into the installations?

@taufiq-husain
Copy link
Author

The badge property isn't updated when using Increment. When I use 1 it starts to work again. I've even tried the same query instead on the _Installation table but it didn't work either (only works with 1 again).

Here's what I changed:

var Installation = Parse.Object.extend("_Installation");
var query = new Parse.Query(Installation, {useMasterKey:true});

from this:

var query = new Parse.Query(Parse.User, {useMasterKey:true});

@flovilmart
Copy link
Contributor

I belive I found the problem.

@taufiq-husain
Copy link
Author

Yay, please let me know how to fix it if you figure it out! =]

@flovilmart
Copy link
Contributor

in the lib folder, locate Routers/PushRouter.js

line 63 replace req.body by req.body.data

let me know

@taufiq-husain
Copy link
Author

For some reason, I can't update the git changes I just made. I'm getting this:

Taufiqs-MBP:getlolapp Taufiq$ git add .
Taufiqs-MBP:getlolapp Taufiq$ git commit -am “Testing”
On branch master
Your branch is up-to-date with 'heroku/master'.
Changes not staged for commit:
    modified:   parse-server (modified content)

no changes added to commit
Taufiqs-MBP:getlolapp Taufiq$ git push heroku master
Everything up-to-date

Sorry, I know this is an unrelated part of the question.

@taufiq-husain
Copy link
Author

Also, please note that it wasn't line "63" for me and I can't find a "lib" folder, I found a "src" folder. Could you please update the master branch and let me know?

@flovilmart
Copy link
Contributor

Try from the fix branch:

cd ./parse-server
git fetch
git checkout flovilmart.FixPushNotifications
git pull
cd ..

git commit -am 'uses fix branch'

@taufiq-husain
Copy link
Author

Still getting issues like this:

Taufiqs-MBP:parse-server Taufiq$ cd ./parse-server
-bash: cd: ./parse-server: No such file or directory
Taufiqs-MBP:parse-server Taufiq$ git fetch 
Taufiqs-MBP:parse-server Taufiq$ git checkout flovilmart.FixPushNotifications
Already on 'flovilmart.FixPushNotifications'
Your branch is ahead of 'origin/flovilmart.FixPushNotifications' by 1 commit.
  (use "git push" to publish your local commits)
Taufiqs-MBP:parse-server Taufiq$ git pull
Already up-to-date.
Taufiqs-MBP:parse-server Taufiq$ cd ..
Taufiqs-MBP:getlolapp Taufiq$ 
Taufiqs-MBP:getlolapp Taufiq$ git commit -am 'uses fix branch'
On branch master
Your branch is ahead of 'heroku/master' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean
Taufiqs-MBP:getlolapp Taufiq$ git push heroku master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 602 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
remote: Git submodules detected, installing:
remote: Synchronizing submodule url for 'parse-server'
remote: From https://github.com/ParsePlatform/parse-server
remote:  * [new branch]      flovilmart.CLPAPI -> origin/flovilmart.CLPAPI
remote:  * [new branch]      flovilmart.FixPushNotifications -> origin/flovilmart.FixPushNotifications
remote:    75ae958..477e978  master     -> origin/master
remote:  * [new branch]      nlutsenko.push -> origin/nlutsenko.push
remote: fatal: reference is not a tree: 4b5a423b087188a08ce5a32f9489f2d66e5033d5
remote: Unable to checkout '4b5a423b087188a08ce5a32f9489f2d66e5033d5' in submodule path 'parse-server'
remote: 
remote: !   Push rejected, submodule install failed
remote: 
To https://git.heroku.com/getlolapp.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/getlolapp.git'

Maybe I'm not allowed to change the server until and unless the master Parse server git is updated?

@flovilmart
Copy link
Contributor

I got to the bottom of it, added more unit tests to prevent regressions

@taufiq-husain
Copy link
Author

I updated to the master branch just now. I tried Push Notification with Increment again and it's still showing the same problems:

2016-03-08T16:09:21.130998+00:00 app[web.1]: APNS Connection 0 Notification transmitted to 5f60cd7d808a582fc0f94482575ca661337f51b9e51b3446627d814a715fb04a
2016-03-08T16:09:21.131179+00:00 app[web.1]: Can not find sender for push type android, {"where":{"username":{"$in":["REDACTED"]},"enabled":true},"data":{"alert":"Message from Test 😋","badge":"Increment"}}
2016-03-08T16:09:21.211369+00:00 app[web.1]: APNS Notification caused error: 8 for device  Device {
2016-03-08T16:09:21.211382+00:00 app[web.1]:   token: <Buffer 5f 60 cd 7d 80 8a 58 2f c0 f9 44 82 57 5c a6 61 33 7f 51 b9 e5 1b 34 46 62 7d 81 4a 71 5f b0 4a>,
2016-03-08T16:09:21.211386+00:00 app[web.1]:   payload: 
2016-03-08T16:09:21.211386+00:00 app[web.1]:    { aps: 
2016-03-08T16:09:21.211385+00:00 app[web.1]:   appIdentifier: 'com.polarhills.LOL' } { encoding: 'utf8',
2016-03-08T16:09:21.211384+00:00 app[web.1]:   connIndex: 0,
2016-03-08T16:09:21.211390+00:00 app[web.1]:         alert: 'Message from Test 😋',
2016-03-08T16:09:21.211391+00:00 app[web.1]:         category: undefined } },
2016-03-08T16:09:21.211391+00:00 app[web.1]:         'url-args': undefined,
2016-03-08T16:09:21.211388+00:00 app[web.1]:       { badge: undefined,
2016-03-08T16:09:21.211394+00:00 app[web.1]:   device: undefined,
2016-03-08T16:09:21.211389+00:00 app[web.1]:         sound: undefined,
2016-03-08T16:09:21.211393+00:00 app[web.1]:   priority: 10,
2016-03-08T16:09:21.211395+00:00 app[web.1]:   truncateAtWordEnd: false,
2016-03-08T16:09:21.211394+00:00 app[web.1]:   compiled: '{"aps":{"alert":"Message from Test 😋"}}',
2016-03-08T16:09:21.211827+00:00 app[web.1]: APNS Connection 1 Notification transmitted to 5f60cd7d808a582fc0f94482575ca661337f51b9e51b3446627d814a715fb04a
2016-03-08T16:09:21.212879+00:00 app[web.1]: APNS Connection 0 Disconnected
2016-03-08T16:09:21.211392+00:00 app[web.1]:   expiry: undefined,
2016-03-08T16:09:21.211396+00:00 app[web.1]:   _alert: 'Message from Test 😋' }
2016-03-08T16:09:21.211393+00:00 app[web.1]:   retryLimit: -1,
2016-03-08T16:09:21.446874+00:00 app[web.1]: APNS Connection 0 Connected
2016-03-08T16:09:51.113594+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/parse/functions/send_push" host=getlolapp.herokuapp.com request_id=cdb53b47-a04a-4357-a0cb-2f7cd3880b21 fwd="24.5.10.195" dyno=web.1 connect=1ms service=30003ms status=503 bytes=0

@taufiq-husain
Copy link
Author

Btw, I did noticed something. When I send push notification with Badge: 1, it doesn't update the _Installation table at all but the actual devices show a badge of 1. It seems to me that Parse is not updating the tables at all before sending it off to APNS whether it's Increment or 1?

@flovilmart
Copy link
Contributor

So now the badge is properly set on the device when you specify a value. That's better.
That's odd that the installation don't get saved, can you make sure the code is run in PushController.js as it seems on my side for the tests that all is fine.

@taufiq-husain
Copy link
Author

I can't really test whether PushController.js is being used or not. Any edits I make is not being updated in the server for some weird reason (also I'm new to git stuff). The master repo is the only one that my server grabs from? My cloud code is being called properly as far as I can see but after that it stops working. I'm pretty sure PushController.js is being called properly because otherwise how else is it pushed to APNS?

@flovilmart
Copy link
Contributor

Can you test locally? I'll try to dig deeper with the APNS provider

@flovilmart
Copy link
Contributor

@taufiq-husain what's the status on that? Did you manage to setup parse-server locally and test that feature?

@taufiq-husain
Copy link
Author

Nope, I'll do it as soon as possible and let you know. Isn't anyone else experiencing the same issue with "Increment" badge?

@taufiq-husain
Copy link
Author

Oh it just fixed itself now on the production server too. I don't know what changed but I updated Parse server last like maybe 4-5 days ago. This issue has been resolved!

@flovilmart
Copy link
Contributor

Yay! Finally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants