0

I am writing a messaging app in Swift where people can chat similar to how text messages or other popular chat apps work. The supporting API is on AWS, written in C#.

There are some points of interest here:

  1. Hoping to avoid third party stuff like Firebase, etc, but open to listening to advice
  2. Alert notifications are not desired for now - no popups, banners, etc. Simply want to show message bubbles arrive in real time on one viewcontroller - if and only if the person is staring at the message screen. If they're somewhere else on the app, nothing happens.
  3. We don't want to prompt the user to ask them if they're OK with this app sending notifications because we're not sending them banners or anything visual, aside from a new chat arriving. Is that a requirement with APNS? I feel like this means someone can say NO, and then we have no way to update the chat app in real time, which won't fly.

    I assume a simple approach would be some sort of timer/loop that runs from the message viewcontroller, where every second or two it hits the API and asks if there are new messages, but that seems inherently wrong to me - the app must be robust, and there could be thousands or hundreds of thousands of people using this - that's a lot of API requests, and in many cases there could be no new messages, thus a wasted call. This is clearly not the way to go, correct?

Question # 1 I was thinking, then, that I should use APNS, however am not sure if it requires you to prompt the user to ask them for permission to receive anything from Apple? Again my concern is the chat bubbles should come in at real time and don't want to give the user the ability to somehow not see these (breaking the app)

If APNS is the way to go, and I must prompt them, then I assume the flow is I will gather my device ids (created in appdelegate, saved in my C# db, and associated to each message thread) and whenever someone types a message, it goes to my API, I save it in the message database table, and then I send out a message to APNS to everyone's device id.

Apple queues this up, and sends to everyone, and if they're on the screen, then the message comes in.

Is this how I should leverage APNS to achieve what I want?

Question # 2 I've seen others recommend using SNS (in conjunction with APNS) however I don't understand why. Doesn't APNS both act as a proper queue, as well as a notification service, thus invalidating the need to use AWS's SNS/SQS at all? It seems redundant to me but maybe I just don't understand the idea behind why you need both technologies.

Appreciate anyone's time in advance if they can shed some light on this for me!

Thanks!

NullHypothesis
  • 4,286
  • 6
  • 37
  • 79
  • Use WebSockets. – stevenpcurtis Oct 04 '18 at 04:35
  • That looks great, thanks. Something like this, even (Starscream) https://www.raywenderlich.com/861-websockets-on-ios-with-starscream - Does WebSockets drain the battery or is the idea that because i'm only doing it on the message viewcontroller (where new chats arrive) that it's limited in battery drain? – NullHypothesis Oct 04 '18 at 12:51

1 Answers1

0

Question 1

Even if you're using WebSockets (As @stevenpcurtis mentioned), you still need to inform user about the fact that user received message when application is in background/suspended. And yes, you must "force" your user to enable notifications for the application and explain why he needs it. Empirically, if user installs messenger, he understands what are notifications used for and why he enables it.

Question 2

From the mobile perspective SNS will still deliver Push notifications when user receives notification while the application is in background or suspended. From the backend perspective you can use SNS.

Conclusion:

From the mobile perspective you have 2 modes:

  • Application is active - it's generally up to you how to receive messages. (Web Sockets, pushes, e.t.c.)
  • Application is in the background or is suspended: You need a tool to inform user about changes without having a control on application. This is the job for Push Notification Service. The way you will send pushes from the backend is up to you.

You can also check This question to get some more information.

Community
  • 1
  • 1
fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30
  • Appreciate your response thanks - I think for me the question becomes what if the user says they do not wish to receive notifications - then I should just terminate the app? Also seems like a bad user experience. I'm wondering what WhatsApp does in terms of this - I feel like if you say 'no' to allowing notifications, their chat app still works (in real time messages still come in) - I doubt they just block your use of the app, and I'm sure they still manage to get messages to arrive in real time if you're on the viewcontroller. – NullHypothesis Oct 04 '18 at 12:50
  • Also one other thing regarding SNS - I still don't follow how it's needed, since I can just push to APNS from my API. What does SNS offer that APNS is not offering? – NullHypothesis Oct 04 '18 at 12:50
  • @NullHypothesis, no! You should never terminate the app. Your responsibility is to warn user, that in case he rejects to allow notifications, he will receive chat messages only while the application is in active state. Regarding SNS - it's just a handy tool. If you can send Pushes from your own api - that would work for you. – fewlinesofcode Oct 04 '18 at 12:52
  • Thanks! I am leaning towards https://www.raywenderlich.com/861-websockets-on-ios-with-starscream do you have any thoughts on why this might be a bad idea? It seems websockets may get me what I want for now! – NullHypothesis Oct 04 '18 at 12:53
  • @NullHypothesis Regarding sockets tutorial - it depends on your requirements. Some people build highly scalable messengers to be able to receive millions of messages daily. For that purposes i would suggest to find either tested enterprise solution or a team of strong professionals. For more modest needs the solution from the tutorial may work just fine. – fewlinesofcode Oct 04 '18 at 12:58
  • Sorry one final question - you said "let them know they only receive notifications in the active state" - how would I achieve that though if the user rejects the popup for allowing notifications? With APNS they have to agree if I want to send them updates even if they're only in active state (looking at the viewcontroller). If they say no, I can't use any aspect of APNS, even in active, no? – NullHypothesis Oct 04 '18 at 13:01
  • @NullHypothesis, you can do it by showing a screen with brief explanation on why do you need Pushes to be allowed and how you gonna use pushes and "Ok" button in the bottom. When user presses Ok, you show system required alert with "Allow notifications" and "Cancel". You can try to install some messenger an check how they do it. It can also help. – fewlinesofcode Oct 04 '18 at 13:12