parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Can't send push to iOS device from Cloud Code.

Open okaris opened this issue 10 years ago • 14 comments

For implementation related questions or technical support, please refer to the Stack Overflow and Server Fault communities.

Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!

Environment Setup

Heroku (Hobby) + mLab (shared cluster) running parse-server-example with parse-server 2.2.0

Steps to reproduce

`var api = new ParseServer({ databaseURI: databaseUri || '...', cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', appId: process.env.APP_ID || '...', masterKey: process.env.MASTER_KEY || '...', //Add your master key here. Keep it secret! fileKey: ...', //This is needed to display old files on Parse's S3 serverURL: process.env.SERVER_URL || 'http://localhost:1337', // Set to correct url from heroku env filesAdapter: new S3Adapter( "...", "...", "...", {directAccess: true, region:"s3-eu-west-1.amazonaws.com"} ), push: { ios: [ { pfx: __dirname + '/development.p12', // Prod PFX or P12 bundleId: 'com.okaris.myapp',
production: false // Prod }, { pfx: __dirname + '/production.p12', // Prod PFX or P12 bundleId: 'com.okaris.myapp',
production: true // Prod } ] }

});`

Logs/Trace

2016-03-21T20:56:16.089931+00:00 app[web.1]: POST /parse/push { host: 'coralline.herokuapp.com', 2016-03-21T20:56:16.089940+00:00 app[web.1]: connection: 'close', 2016-03-21T20:56:16.089941+00:00 app[web.1]: 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.1 (NodeJS 5.8.0)', 2016-03-21T20:56:16.089942+00:00 app[web.1]: accept: '*/*', 2016-03-21T20:56:16.089943+00:00 app[web.1]: 'content-type': 'text/plain', 2016-03-21T20:56:16.089951+00:00 app[web.1]: 'x-request-id': '9efc6deb-5c34-4e21-9dc1-8c7594f14090', 2016-03-21T20:56:16.089952+00:00 app[web.1]: 'x-forwarded-for': '54.74.165.67', 2016-03-21T20:56:16.089953+00:00 app[web.1]: 'x-forwarded-proto': 'https', 2016-03-21T20:56:16.089953+00:00 app[web.1]: 'x-forwarded-port': '443', 2016-03-21T20:56:16.089954+00:00 app[web.1]: via: '1.1 vegur', 2016-03-21T20:56:16.089954+00:00 app[web.1]: 'connect-time': '0', 2016-03-21T20:56:16.089955+00:00 app[web.1]: 'x-request-start': '1458593776087', 2016-03-21T20:56:16.089956+00:00 app[web.1]: 'total-route-time': '0', 2016-03-21T20:56:16.089956+00:00 app[web.1]: 'content-length': '399' } { 2016-03-21T20:56:16.089957+00:00 app[web.1]: "where": { 2016-03-21T20:56:16.089958+00:00 app[web.1]: "user": { 2016-03-21T20:56:16.089958+00:00 app[web.1]: "__type": "Pointer", 2016-03-21T20:56:16.089959+00:00 app[web.1]: "className": "_User", 2016-03-21T20:56:16.089960+00:00 app[web.1]: "objectId": "BUCrtfWPdz" 2016-03-21T20:56:16.089960+00:00 app[web.1]: } 2016-03-21T20:56:16.089961+00:00 app[web.1]: }, 2016-03-21T20:56:16.089962+00:00 app[web.1]: "data": { 2016-03-21T20:56:16.089962+00:00 app[web.1]: "alert": { 2016-03-21T20:56:16.089963+00:00 app[web.1]: "loc-key": "LikeNotification", 2016-03-21T20:56:16.089963+00:00 app[web.1]: "loc-args": [ 2016-03-21T20:56:16.089964+00:00 app[web.1]: "okaris", 2016-03-21T20:56:16.089965+00:00 app[web.1]: "O" 2016-03-21T20:56:16.089965+00:00 app[web.1]: ] 2016-03-21T20:56:16.089966+00:00 app[web.1]: }, 2016-03-21T20:56:16.089967+00:00 app[web.1]: "badge": "Increment", 2016-03-21T20:56:16.089967+00:00 app[web.1]: "sound": "PopDing.caf" 2016-03-21T20:56:16.089968+00:00 app[web.1]: } 2016-03-21T20:56:16.089969+00:00 app[web.1]: } 2016-03-21T20:56:16.092150+00:00 app[web.1]: response: { 2016-03-21T20:56:16.092160+00:00 app[web.1]: "response": { 2016-03-21T20:56:16.092161+00:00 app[web.1]: "result": true 2016-03-21T20:56:16.092162+00:00 app[web.1]: } 2016-03-21T20:56:16.092163+00:00 app[web.1]: } 2016-03-21T20:56:16.095961+00:00 app[web.1]: ##### PUSH OK

Server logs "PUSH OK" but I don't see any APNS Connection logs, no push is delivered. Tried with both production and development certificates. Certificates don't have passwords. Tried using empty android push config and not. Tried using CURL with same result.

Cloud Code:

var pushQuery = new Parse.Query(Parse.Installation, { useMasterKey: true }); pushQuery.equalTo('user', user); Parse.Push.send({ where: pushQuery, data: { alert: { "loc-key": "LikeNotificationNoContent", "loc-args": [sender.get('screenName')] }, badge: "Increment", sound: "PopDing.caf" } }, { success: function() { console.log('##### PUSH OK'); }, error: function(error) { console.log('##### PUSH ERROR' + error); }, useMasterKey: true });

okaris avatar Mar 21 '16 21:03 okaris

Can you get the content from the _PushStatus collection?

flovilmart avatar Mar 22 '16 14:03 flovilmart

@flovilmart

{ "_id" : ObjectId("56f15dfd6596e411006a21dd"), "objectId" : "A0EgU94oN9", "pushTime" : "2016-03-22T15:00:13.685Z", "_created_at" : ISODate("2016-03-22T15:00:13.685Z"), "query" : "{\"user\":{\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"sdOD1uHCCa\"}}", "payload" : { "title" : "The Shining", "alert" : "All work and no play makes Jack a dull boy." }, "source" : "rest", "title" : null, "expiry" : null, "status" : "succeeded", "numSent" : 0, "pushHash" : "f41355801d168ad58b479075e9a8576e", "_wperm" : [], "_rperm" : [], "numFailed" : 0 }

okaris avatar Mar 22 '16 15:03 okaris

ok, seems that either the status is not properly reported OR your query don't match any user. Can you verify the latter? and that the installation properly has a deviceToken?

numSent and numFailed are properly set, that means the push has properly callback'd, but no responses were set

flovilmart avatar Mar 22 '16 15:03 flovilmart

@flovilmart The query matches a user. I have got this from a CURL request and I have set the user to the user on my own device and made sure it has the right deviceId (and there is only one installation with these values).

I also don't see any logs about APNS Connection even if I have VERBOSE=1 set

okaris avatar Mar 22 '16 15:03 okaris

I'll have a look. The query should match an installation.

flovilmart avatar Mar 22 '16 15:03 flovilmart

Installation:

{ "_id" : "XYjSEioN9U", "timeZone" : "Europe/Istanbul", "appVersion" : "25", "appName" : "***", "deviceType" : "ios", "badge" : 1, "installationId" : "027cb5e6-da7e-43a3-a46c-14a238640270", "appIdentifier" : "com.okaris.***", "parseVersion" : "1.12.0", "deviceToken" : "4626eeff**************************************059ae14802", "localeIdentifier" : "en-TR", "_updated_at" : ISODate("2016-03-21T18:38:14.936Z"), "_created_at" : ISODate("2016-03-21T13:24:35.242Z"), "_p_user" : "_User$sdOD1uHCCa" }

okaris avatar Mar 22 '16 15:03 okaris

sounds valid... I'll have a deeper look

flovilmart avatar Mar 22 '16 15:03 flovilmart

I'm having the same exact problem but with GCM, any updates?

firaskafri avatar Mar 24 '16 17:03 firaskafri

I'm running on 2.2.2 and I have the same issue with GCM. No logs at all. But I get APNS connections logs, but the notification never reaches the phone. They time out one hour after sending. I have not reconfigured my ios app since migration, except for the server URL. That might be the issue under iOS. For android I have no clue. I double checked all configurations. How can I get a hold of the pushStatus?

jherrmann avatar Mar 24 '16 22:03 jherrmann

@flovilmart opened the issue also on the new repo on parse server modules, but currently even if i state my dependency as 2.2.2 i can't get the version with push on a seperate module, so i am writing here. where are we with this? I am seeing 3-4 more people having a similar problem. Thank you

okaris avatar Mar 27 '16 16:03 okaris

@okaris this is normal, we haven't released the change to npm yet. However, if you want to use the parse-server-push-adapter from parse-server-modules, you can still do it.

Add it as a dependency, and initialize it With the same options you'd pass to the push options.

Then pass the initialized push adapter to the push option when initializing ParseServer

flovilmart avatar Mar 27 '16 16:03 flovilmart

@okaris @flovilmart @firasalkafri

NOTE: My server is a fork of this repo: https://github.com/codepath/parse-server-example

It has just about everything set up for iOS/android.

I was having this exact problem with this code in my index.js:

    var pushConfig = {};

    if (process.env.GCM_SENDER_ID && process.env.GCM_API_KEY) {
       pushConfig['android'] = { senderId: process.env.GCM_SENDER_ID || '',
                          apiKey: process.env.GCM_API_KEY || ''};
    }


pushConfig['ios'] = [
    {
        pfx: __dirname + '/....p12', // P12 file only
        bundleId: 'com.baymitchell.myapp',  // change to match bundleId
        production: false // dev certificate
    }
]


    var filesAdapter = null;  // enable Gridstore to be the default
    if (process.env.S3_ENABLE) {
        var S3Adapter = require('parse-server').S3Adapter;

        filesAdapter = new S3Adapter(
            process.env.AWS_ACCESS_KEY,
            process.env.AWS_SECRET_ACCESS_KEY,
            {bucket: process.env.AWS_BUCKET_NAME, bucketPrefix: "", directAccess: true}
        );
     }

    var api = new ParseServer({
      databaseURI: databaseUri || 'myMongoDBURI',
      cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
      appId: process.env.APP_ID || 'my-app-id',
      masterKey: process.env.MASTER_KEY || 'my-master-key', //Add your master key here. Keep it secret!
      push: pushConfig,
      filesAdapter: filesAdapter,
      serverURL: process.env.SERVER_URL || 'my-server-url'  // needed for Parse Cloud and push                 notifications

    });

I am also using a fork of the parse-server-example, so I couldn't understand why the notifications weren't going through. I simply uploaded my .p12 file to my fork and boom, the notifications started coming through. View the picture to see where I uploaded my.p12 development certificate! screen shot 2016-03-27 at 8 13 40 pm

baymitchell12 avatar Mar 28 '16 01:03 baymitchell12

@okaris can you retry today, updating parse-server to the latest version? We have a numerous of reports that with a proper configuration, push are being correctly sent.

flovilmart avatar Apr 03 '16 15:04 flovilmart

@flovilmart i followed up on the adapter repo. Eveything is ok now you can close the issue. Thanks!

okaris avatar Apr 03 '16 16:04 okaris