0

users

enter image description here

posts

enter image description here

comments

enter image description here

unread_messages

enter image description here

Partial Desired Outcome

enter image description here

Full Desired Outcome

I want my app's badge icon to show a number that represents the number of unread comments the users has. The app is a Post/Comment style application. If a User Alice makes a post for example, and user Bob comments on it, a POST will be sent to the backend JSON API to the /comments URL. It will save the comment, add 1 to the unread_messages row for user Alice, and send a push notification to APNS setting the badge equal to the count in the unread_messages table for Alice.

The reason for this unread_messages table is to prevent having to do an INNER JOIN on posts and comments, which are likely the two biggest tables in the database. If Alice has 500 posts, it could be a large join and I've been told count()'s are an expensive operation.

Client Side

In the iOS app, the badge will equal the value sent to it by APNS. When Alice opens the app, I want the 1st tab of the 3-tab tabBar to show a badge of the amount of unread_messages. For this, it will not rely on the value on the apps badge, but rather make a call to the backend API for the value in unread_messages for Alice. It will return 3 in this case. This value will also be used as a visual indicator in the "My Posts" row seen in the image above.

Now when Alice taps on 'My Posts', she will be taken to a new view showing all her posts. She will see her Post 1 and Post 2 as 2 separate rows. There will be a visual indicator beside each showing how many unread messages each has. So this view will need to pull in all Post information where user=alice, as well as all the comment information for all those posts, including the amount of read=false. This will allow us to display a visual indicator of 2 unread for Post 1, and 1 unread for Post 2.

If Alice views Post 1, it means she will be viewing 2 unread messages. A call to the server will be made to decrement unread_messages by the amount she is viewing, and set the read column on comments to true. If she then backs out, only Post 2 will have a visual indicator left, showing it's 1 unread message. The first tab will also have a badge of 1. The apps badge will be updated as well and if she closes the app, the badge will also only say 1.

Is this the best way to design this? Are there way too many server calls going on here, joins, etc? Is there a more efficient way of designing this?

Thanks for reading!

chris P
  • 6,359
  • 11
  • 40
  • 84

1 Answers1

1

Since push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.

But you can send the badge number in the payload of the push notification, but the you will have to do the calculation server side.

You should read :Local and Push Notification Programming Guide and specially the The Notification Payload.

The payload could look like this:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9
    }
}

Now the app application badge icon will show 9. you can find similar answer here

Community
  • 1
  • 1
bLacK hoLE
  • 781
  • 1
  • 7
  • 20