iPhone background operations/daemon with live chat module. Keeping the app alive? - iphone

I am building a live chat app for the iPhone, and for this it is necessary to ensure that the operator is online and to keep the flow of data going.
After much search it seams to be only two options for similar kind of behavior;
UILocalNotification, only works if I have some scheduled information notice to be sent
Push Notification, for pushing data to the phone
The problem with push notification seams to be that I cannot ensure that the user is available, or in any way talk with the app without the user re-opening it. This way it seams impossible for me to know if the user is online, to update data in the app without the user having to manually open it, etc.
So, what I ask for, is it in any way possible to keep the app active in the background thus ensuring the operator is online and notify of incoming chat sessions?
Thanks a lot for your help guys!

Unfortunately the answer is no. I take it you mean text chat and not VoIP (which CAN run in the background)? Your best bet would be Push Notifications, as you would not be able to monitor anything from the app itself when it is in the background.

Related

Updating Chat App in Real Time Using APNS (with or without AWS SNS)?

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:
Hoping to avoid third party stuff like Firebase, etc, but open to listening to advice
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.
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!
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.

How to keep user notified that application is running in background?

Since few days i am searching for the functionality which will allow me keep user posted that application is running in background. I have attached a !image for what exactly i am looking for. i tried googling but could not get exactly what I need. when i tap on the flashing red bar it takes me back to the application.
Thanks in advance.
The red banner you pictured is provided by the system, is shown only if your application uses background audio recording (see AVAudioSession), and doesn't provide the opportunity for you to choose what happens when the user taps it.
Unless your app fits into one of a few specific classes, it doesn't actually "run" while in the background. Instead, it's "suspended" -- still in memory, but gets no CPU time. What happens outside of your app is thus up to the system, not to you... the only way to show a banner that will launch your application is to use a push notification service or UILocalNotification, but those banners are only shown briefly, and you don't get to control their duration. What you seem to be specifically asking for isn't possible using public API.
The kind of notification you want isn't supported by the current iOS for third-party developers.
If you want that kind of functionality then implement Apple Push Notification service through
this you can first give message to Apple push notification service. then Apple service
automatically generate notification for your App as you want.

can we send messages to user even when the application is closed in iphone sdk?

i m making an application where data is accesed from website and displayed with an application.i have made an action which will tell the user that new data has arrived.this will work properly if the application is open .but if the application is closed than ,is there any way to tell the user that new data has arrived ,,so that he can open the application and check the data?
If you are using the Apple Push Notification Service (APNs), your messages will be delivered whether the application is running or not. For information on how to control what information is presented to the user, read the Apple Push Notification Programming Guide.
You should use Apple Push Notification Service, like codelark said.
I would recommend looking into Urban Airship for help getting started. It's a third party service, but it makes things much easier. Urban Airship does have their own tutorials and code samples which may be easier than Apple's.
As a follow up to the reference to apple push notification, as of ios4.0 I believe you, you may have a few more options, 1) you can send local notifications (just like push notifications, but they originate from inside your app) that could be timed to be delivered even if the app is not running..assuming you know approximately how long it will take for data to arrive. 2) if your data update will occur soon after the app closed.. your app can request a certain amount of time to complete an operation (even though the user has closed the app) and wait for the data, then send a local notification to tell the person to come back into the app. 3) if your functions based on gps updates, music streaming, or voip you can set a flag so your app continues to run in the background
sorry for the unstructuredness of the answer, this was just off the top of my head, hope it helps

Question regarding iphone allowance of custom notifications

I have an app that I am working on, and part of its main functionality is to alert the user to do something. So even though they aren't in the app, I want to be able to pop up an alert from the app, reminding them to do something. Is that allowed with the iPhone sdk? Maybe it isn't even a big deal at all, but for some reason I was thinking that it would require background processes or something that may or may not be possible. Anyone who has any thoughts about how this would be implemented would be greatly appreciated. Thanks!
Check out the Apple documentation on push notifications. Short of jailbreaking and distributing your app outside the App Store, there is no way to run background processes at this time.
It is allowed through notifications, though you will need a server to actually send the notifications to the user. There is no limit to the number you can send, although the user may very well decide to shut off notifications or delete your app altogether if you are too spastic with them. Make very sure the user understands the notification volume they will receive and agrees to it...
The way the system works is the user gets a notification message (and/or sound) and can decide to open your app or not, as the time of notification.

How can I run an app at a specified time on the iPhone?

I'm developing a todo list application. I'm looking for any way to alert the user when a task becomes due, even if the app is not running. Is there any way to set the program to run at a specified time w/out user interaction? Or a way to bring up an alert anyway?
Edit: How can I add an item to the calendar?
No, not until the push notification service gets released.
Your best bet right now is allowing users to add reminders to the Calendar - without the push service, there's no notifications without your app running actively.
As has been made very clear by Steve Jobs himself, the iPhone SDK will NOT support background processes. In addition, there is no API to access the calendar on the iPhone.
If these things are important to you, you should file an enhancement request:
Apple Bug Reporter
But even once push is released, that won't enable you to have the application independently alert the user. You would have to run a server that would push notifications to people once a task is approaching due, which means you would have to have everyone's task list synced to your server.