Skip to content

Commit

Permalink
Merge pull request #323 from johanforssell/patch-1
Browse files Browse the repository at this point in the history
README: Example on getting the tokens you should remove
  • Loading branch information
hypesystem authored Jun 1, 2018
2 parents debc2b2 + 4b3d9be commit a63a4b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ sender.send(message, { registrationTokens: registrationTokens }, 10, function (e
if(err) console.error(err);
else console.log(response);
});

// Q: I need to remove all "bad" token from my database, how do I do that?
// The results-array does not contain any tokens!
// A: The array of tokens used for sending will match the array of results, so you can cross-check them.
sender.send(message, { registrationTokens: registrationTokens }, function (err, response) {
var failed_tokens = response.results // Array with result for each token we messaged
.map((res, i) => res.error ? registrationTokens[i] : null) // If there's any kind of error,
// pick _the token_ from the _other_ array
.filter(token => token); // Remove all the null values
console.log('These tokens are no longer ok:', failed_tokens);
});
```
## Recipients

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"Chirag Choudhary <chirag200666@gmail.com> (https://github.com/chirag200666)",
"Alexander Amin <alexander.amin@high5-it.de> (https://github.com/AlexAmin)",
"Gaurav Nolkha <gaurav@swiftday.com> (https://github.com/vibgy)",
"Jan Kowalleck <jan.kowalleck@gmail.com> (https://github.com/jkowalleck)"
"Jan Kowalleck <jan.kowalleck@gmail.com> (https://github.com/jkowalleck)",
"Johan Forssell <johan@forssell.me> (https://github.com/johanforssell)",
],
"repository": {
"type": "git",
Expand Down

0 comments on commit a63a4b4

Please sign in to comment.