AWS Mobile Push with users that may be logged into multiple devices
Asked Answered
B

3

15

Our apps are being developed for both Android and iOS. We are using AWS SNS Mobile Push to push messages to both GCM and APNS. The back end is PHP and so it uses the AWS PHP SDK.

Until now, our system has been saving 1 Endpoint ARN per user. We then broadcast a Mobile Push message directly to this Endpoint ARN.

The question:

It would be strange if a user were logged into our app on multiple devices and did not receive push notifications on all of them. So - we're going to have to change something.

How, in AWS Mobile Push, is the concept of 'one user, multiple devices (and potentially multiple platforms) handled?

Does our system have to maintain a one-to-many association of user-to-EndpointARNs (i.e. start saving multiple EndpointARNs per user so that we may push messages to all of them sequentially)?

Or should I be looking into the 'Topics' concept that Mobile Push provides (I'm confused here - do some people use one topic per user, and then push messages to the topic itself?)..

Lastly - I guess as a bonus question - is it normal for people using the PHP AWS SDK to include both APNS and GCM attributes in the Message payload array? We haven't been keeping track of 'which type of device each user uses'. We've just been saving an Endpoint ARN per user. And I guess the thought was to just cover all our platform bases (APNS, APNS_SANDBOX, GCM) when we're pushing a message to an endpoint.

I've been doing a lot of searching on the 'one user with multiple devices' topic re: Mobile Push with AWS SNS, and really the results have been quite unhelpful.

Help please :(

Thanks!

Beetle answered 5/2, 2016 at 1:9 Comment(2)
I think you need to send seperate message for multiple platform devicesSubvention
@IjasAhamed so, AWS Mobile Push users typically keep a DB table which maps between users and their (multiple) Endpoint ARNs, to support users that have installed the app on multiple devices?Beetle
C
1

Once you send SNS Push message , you will get success or failure reason. Could you please check your logs and share to identify exact issue.

Cloudwatch : SNS publishes Cloudwatch metrics for number of messages published, number of successful notifications, number of failed notifications and size of data published. Metrics are available on per application basis. You can access Cloudwatch metrics via AWS Management Console or CloudWatch APIs.

Direct addressing: Direct addressing allows you to deliver notifications directly to a single endpoint, rather than sending identical messages to all subscribers of a topic. This is useful if you want to deliver precisely targeted messages to each recipient. When you register device tokens with SNS, SNS creates an endpoint that corresponds to the token. You can publish to the token endpoint just as you would publish to a topic. You can direct publish either the text of your notification, or a platform-specific payload that takes advantage of platform-specific features such as updating the badge count of your app. Direct addressing is currently only available for push notifications endpoints.

Official documentation, "When a topic is created, Amazon SNS will assign a unique ARN (Amazon Resource Name) to the topic.

https://aws.amazon.com/sns/faqs/

Confide answered 3/3, 2016 at 12:31 Comment(0)
D
1

I have a solution for this issue as you already know ARN is associated with single device token so you must be manage it own your own to send push to same user with multiple device.

My approach is to create 2 table in mysql or whatever database you are using 1. For APNS or, APNS_SANDBOX having details like user_id(local), device token, endpoint ARN, status etc (EG : sns_apns) 2. Same for GCM or BAIDU you have to create a table having user details with endpoint ARN(EG : sns_gcm)

Now every time when you send push to a particular user just write a code something like this

Switch($platform) {
   case 'APNS':
   case 'APNS_SANDBOX':
       Select all users from sns_apns by login id.
       Create a message and send it to all users having same user id 
   case 'GCM':
      Select all users from sns_gcm by login id.
      Create a message and send it to all users having same user id 
}
Daron answered 16/6, 2017 at 5:24 Comment(0)
A
0

I haven't tried this but to solve your problem I would keep a map of the user's cognito userID and corresponding endpoint ARN for each major app defining transaction done by the user. If the endpoint already exist then no need to save it. But if for this userID another endpoint ARN is notice then save, update, add or associate this new endpointARN with userID in DynamoDB as a @Document attribute. Then at anytime just broadcast to all endpointARN associated to the userID in DynamoDB.

The mysampleapp mobile hub example codes are useful for quick manipulation. For android:

Get the endpointARN in app like this:

  PushManager pushManager;
  String userDeviceEndPoint;
  pushManager = AWSMobileClient.defaultMobileClient().getPushManager();
  userDeviceEndPoint =  pushManager.getEndpointArn();

You can update DynamoDB using the update save behaviour to ignore if an already existing endpoint is noticed for the user:

 DynamoDBMapper mapper = new DynamoDBMapper(ddbClient, new   DynamoDBMapperConfig(DynamoDBMapperConfig.SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES));

Not sure how to do this in PHP though. Hope this idea helps.

Aindrea answered 13/7, 2016 at 4:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.