Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Push Notification: cannot find vaild connection

Tags:

parse-server

I'm trying to setup push notifications on my local parse server. I get this error when trying to send a push:

parse-server-push-adapter APNS cannot find vaild connection for 9a86...21

(The error repeats for every installation device token.)

Any ideas?

My server code:

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',  
  liveQuery: {
    classNames: ["Mission"]
  },
  filesAdapter: new S3Adapter(
    process.env.S3_ACCESS_KEY || '',
    process.env.S3_SECRET_KEY || '',
    process.env.S3_BUCKET || '',
    {directAccess: true}
  ),
  push: {
    ios: {
      pfx: 'certificates/development.p12',
      bundleId: 'co.example.myApp',
      production: false // Dev
    }
  }
});

I'm pushing from my cloud code:

var installationQuery = new Parse.Query(Parse.Installation);
installationQuery.containedIn('user', specificUser);
Parse.Push.send({
  where: installationQuery,
  data: {
    "alert": "Loren ipsum ",
    "id": MyCustomId
  }
}, { useMasterKey: true }, {
  success: function() {
    console.log("Push was successful!");
  },
  error: function(error) {
    console.error(error);
  }
});
like image 629
cassiozen Avatar asked Mar 30 '16 05:03

cassiozen


1 Answers

What cause the error is that you have a device in the installation table that matched the filter on the push request that is no longer registered in Apple for your app. When Apple receives a request for a notification to a device that is no longer registered to your application it returns that message to indicate you should take some action if it continues to happen.

In my case I have four devices registered in the installation table that matched my push filter and two of those devices are no longer registered in Apple for my app so every time I push it get that error for each of invalid installations.

Error Message from the Parse Server Log

Matching devices in the dashboard

I'm not sure why it happens but I've seen the following scenarios that causes a new installation record to be created that invalidates the prior installation. It seems like something the parse service could monitor and take action for after getting so many errors for that device token with no successful pushes between errors.

  1. The user deletes and re-installs the app
  2. The user updates their iOS version and the deviceToken value is changed.
  3. The connection url to the parse service is updated in the app by changing a configuration setting without having to reinstall the app.

To resolve the errors you simply need to remove the installation that matches the deviceToken in the error message

like image 89
Aaron Avatar answered Dec 23 '22 21:12

Aaron