Turn based game - Can I send a push request to urban airship from my app?

I have an IOS, multiplayer turn-based game already made. My goal is to have a push notification sent to a device when it is the other player's turn. Is it possible to trigger an airship push notification to the other player from within the app? I can pull the opponents device token from a Firebase DB if needed.

 

Ive got a sample app running on urban airship, but at the moment I can only seem to broadcast notification messages to all devices, or manually by manually entering selected devices.

 

Thanks.

 

 

Didn't find what you were looking for?

New post

Comments

1 comment

  • Brendan,

    We've definitely had quite a few apps similar to yours that notify a user when their friend/enemy/friendenemy has taken a turn, or when it is the users turn.

    In order to accomplish that use case, you can do it either one of two ways.

     

    The first, and probably the recommended route, is to set up to service that the app talks to. When the user takes their turn, the app will in turn communicate to the service that their turn is up, and it is now the other player's turn. The service will then determine who that user is, and their respective Device Token. In your case, you would be querying your Firebase DB. Once that is determined, you can then send a push notification via the Urban Airship API.

     

    The second method, which while it is doable, it may become a little unmanageable. I'll get to that in a bit.

    For this to work, what you would need to do is utilize Urban Airship Tags within your application.

    So, let's say Player 1 starts a game with Player 2. Depending on how you want to name things, Player 1's app would set a tag within the app, something like player_2_<Player ID>, where Player ID is a unique id specific to Player 2 and their device. Similarly, Player 2's app would set a tag with Player 1's ID (player_1_<Player ID>). In addition to that tag, you would also add another tag to determine whether or not it is that player's turn. So, let's say Player 1 took a turn, so now it is Player 2's turn. You'll need to determine who Player 2 is, and change a tag on their device to indicate it is their turn (your_turn). You can then use either our automation system to send out to any user who gets that tag added to their device, or have a service that monitors those tag changes and send out a push to that user. When that users turn is up, we'll then remove that tag from their device and add a different tag (their_turn). Once a game is over, you'll want to remove both tags from the device to make way for the next game.

    Now, this can get pretty complex if it involves multiple games at one time, so the tagging strategy here is not the best approach.

     

    The first way I described above is the best way you would be able to accomplish your use case. The only missing piece is setting up that service to listen for communication from players devices when a turn is up. Since you've already got the database spun up, it shouldn't be much of an issue for finding out who those users are, and then using the API to send to those users.

    0

Please sign in to leave a comment.