Support for new api
jkeam opened this issue · 10 comments
In the docs there seems to be a better endpoint that allows an array of messages and a more complex message type that includes things like badges. Are there plans to update this gem to support that?
@jkeam thanks for impl v2.
@jesseruder - Is this repo not anymore official supported? Last update was in 2016 ... and what can we do to keep this up to date?
I am still having trouble with pushing groups of messages:
messages = []
new_users.each do |id|
user = User.find(id)
@chat.users << user
if id != current_user.id && token = user.token
message = "You have been invited to the group #{@chat.title}! Woo!"
messages.push({
to: token,
sound: 'default',
body: message
})
end
end
message_arrays = messages.each_slice(100).to_a
message_arrays.each do |notifications|
exponent.publish notifications
end
I ran bundle update
, does that give me the latest version of the gem from the pull request? I dont understand how to fix this
right now it only works with single notifications
No, the latest version of the gem has not been published yet. You can see here:
https://rubygems.org/gems/exponent-server-sdk
The latest gem is from 2016.
0.0.2 - June 20, 2016 (6.5 KB)
As a result, you need to modify your Gemfile to point to this repo's master branch. You can see how to do that here:
http://bundler.io/v1.12/git.html
Let me know if this still doesn't work for you.
I got it to hit this new version but for some reason the publish is only working if there is one element in the array of messages. If there are multiple it is not working. I have it set up with the code structure above.
UPDATE:
Im not sure if this matters, but in the rails console when I do array.to_json
it puts out with a bunch of " and \ like so:
"[{\"to\":\"token\",\"sound\":\"default\",\"body\":\"message\"},{\"to\":\"token\",\"sound\":\"default\",\"body\":\"message\"}]"
If it is array.as_json
it prints out cleaner:
[{"to"=>"token", "sound"=>"default", "body"=>"message"}, {"to"=>"token", "sound"=>"default", "body"=>"message"}]
In the updated gem file we are calling .to_json on the messages array before calling the API. Do you think this might be the problem?
UPDATE:
It is working on iPhone but not working on Android unless there is only one message in the array
hmm. so I tried changing it to as_json but the api would not accept it. I guess it needs to be to_json.
It's weird tho, this is working for me on iOS with batching notifications but it does not work on Android unless there is only one item in the messages array. It works on iOS if there are multiple or just one.
When logging all incoming notifications, the notification is not even being received by the Android phone unless it is the only message in the messages array. Again, iPhone is working fine tho.
I guess I can send out the messages individually...I'm concerned that could really slow down the app depending on how many messages are being sent out at once though. I really like that we are able to batch them in groups of 100.
UPDATE:
woo! its fixed
I didnt make any changes to the gem, I just changed the way I was building out the messages:
Correct:
messages.push({
'to': token,
'sound': 'default',
'body': message
})
vs.
Incorrect:
messages.push({
to: token,
sound: 'default',
body: message
})
I am not sure that is the reason it works, but that is the only thing I changed and it is working.
I tested this just now and everything seems to work as expected.
I'm a little confused that it works on ios and not android. My confusion is compounded by the fact that this gem runs on neither device. This gem would run in the server (in say rails or something).
All this gem does is deliver the data to expo's servers and then expo handles the rest of the magic to get it from their servers to the various devices.
To narrow the problem down, I would have your rails app output the payload that it's getting from both ios and android. If the payload is identical in both cases, you can be pretty sure that the error is happening further downstream.
If the payloads are not identical, then go into your client code and see if you can make the payloads the same.
You can also test this outside of the scope of this gem. Use Postman or similar and just issue a POST to
https://exp.host/--/api/v2/push/send
with the following headers:
accept: application/json
accept-encoding: gzip, deflate
content-type: application/json
where the payload looks like:
[{
"to": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
"body": "Hello world!"
}, {
"to": "ExponentPushToken[yyyyyyyyyyyyyyyyyyyyyy]",
"body": "You've got mail"
}]
Make sure to use your problematic android tokens.
yea i updated the post this is resolved now. I'm not sure why my solution above works but it does. The other way just isnt working on android.
ah perfect! glad it worked for you. i'm going to mark this as closed.