urbanairship / ruby-library

A Ruby wrapper for the Urban Airship API.
Other
200 stars 118 forks source link

Push alias needs to be a string for android #52

Closed jlforever closed 9 years ago

jlforever commented 10 years ago

Firstly, thanks for creating this gem, it works out pretty well. But we did encounter one subtle issue and want to get some insights regarding the issue.

Our push audience includes both android and iOS devices. We decided to use the User#id as the push alias. Our notification payload is agnostic in that it will include common blocks for things like alert and aliases as well as device dependent sections like ios and android to make sure users with multiple devices can receive pushes for all of his/her devices. Ex:

{
  aliases: [user.push_alias],
  alert: notification_message,
  ios: {
    badge: '+1',
    extra: {
      url: action_url
    }
 },
 android: {
   extra: {
     url: action_url
   }
 }
}

For some reason, push to iOS via aliases => [1234] was able to go through, but push to android requires the push alias to be in string format in order to go through, ex: aliases => ['1234']. Using string for both iOS and android was fine so we decided to go with that.

But, just curious whether this is something on the gem side instead of UA as the api specification for UA does not indicate a strict format difference for the push alias that is used for iOS vs android.

Thanks.

trek commented 9 years ago

Did this stop being an issue?

jlforever commented 9 years ago

@trek I have recently migrated away our company's push notification stack from using Urbanairship and built an in-house push notification stack that uses the grocer and gcm gem.

So going back to your question, before we switched-off urbanairship gem, we were still passing the alias as string, in the format of something like:

{
  aliases: [user.push_alias] # User#push_alias returns the user id as a string
  ...
}

So that means, there weren't any resolution in regard to this issue. However, I vaguely recall, when I tested this more after I raised the issue, I noticed a separate problem for notification payload that is intended to be handled by the UA gem to push to both ios and android device. That issue was the the alert cannot be living in the top level and badge cannot be living in the ios inner hash, but instead ios alert and ios badge need to be defined within aps inner hash. And a separate alert will need to be defined in the android inner hash. I have a hunch that the push alias issue might be the wrong issue I was chasing and the overall issue was the alert and badge key/values are not appropriately placed.

Unfortunately, it will be difficult for me to test this theory by converting User#push_alias to just pass back the id as integer as I have removed the UA gem and completely revamped the push payload, but I think a general rule for a push notification payload that needs to deliver push to both ios and android devices, would be something like:

{
  aliases: [user.push_alias],
  aps: { alert: alert_message,
    badge: badge_count
  }
  ios: {
    extra: {
      url: action_url
    }
 },
 android: {
   alert: alert_message,
   extra: {
     url: action_url
   }
 }
}

At least that worked perfectly for us using the UA gem for the 6 months when we were on UA. Oh, by the way, thanks for providing this gem, it worked out great for us while it was in prod.