iPhone - how to be notified of call completion - iphone

I'm developing an application that needs to take action on completed phone calls, preferably right after the call ends but minimally once per day.
I've read up on the new CoreTelphony framework, and it seems I can get call events if my app is active, but I don't see how to launch/wake my app when a call ends if my app is not the foreground app. I also don't see how any of the new pseudo-background "modes" would allow my app to listen for these events in the background. Do any of you know how this might be done?
If post-call processing isn't possible, then I'd like to figure out a way to automatically wake my app up once per day, pull all of the call events since the last wakeup, and process them. I know how I might do this with Push or Local notifications, but my understanding is that those require user action to continue; in this case, I just want the processing to happen automatically. Is there a mechanism that would enable this?
Thanks,
Dan

You can't launch your app without user interaction.
Push / Local notifications aren't for this kind of thing, they're for letting the user know about event.
On a non-jailbroken device there is no way to do what you want to do.

Related

Flutter: automatically resume app from background service

Is there a way to automatically resume a flutter app from a paused or inactive lifecycle state with a background service?
Similar to when the WhatsApp app received a call while it was paused or inactive.
No, you can not simply wake up the app from a service. This would open the door for all kinds of spam apps and security risks. You need to specifically register it as VOIP app using CallKit or something like SIP on Android to receive incoming calls.
For other things you can use push notifications but that won't start your app. The user always has to click on the notification that you display.
You need to use a couple of things together:
Use push notifications to wake up your app:
https://pub.dev/packages/firebase_messaging
To start your app using push notifications refers to this post:
https://stackoverflow.com/a/48405551/4335775
Use CallKit (IOS) or ConnectionServices (Android) to show the upcoming call screen. By the day of this answer there are only a few packages to handle these things, here is one that can handle both platforms:
https://pub.dev/packages/flutter_callkeep
If you want a completely different thing and need to run some background process, there are bunch whole of things you should know first. I suggest beginning here: https://flutter.dev/docs/development/packages-and-plugins/background-processes
Here is a usefull package to work with background processes that should be constantly running:
https://pub.dev/packages/background_fetch
The app can only be waked up with explicit commands. The user must hit the button. And there are ways to handle the input, messages may pass parameters, you can save the previous state in the database or shared preferences, etc.

iOS chat-app: How do I notify the user that the app will not function anymore if the user leaves the app?

I'm developing a chat-app for iOS that must use an existing server API. The way it works is pretty straightforward: the app checks every given interval whether there are new messages on the server and displays them, plus, it sends the server new messages that the user typed.
When the user starts 'multi-tasking' or presses the home button, my app will go to the background and therefore will not be able to check the server for new messages. The server will automatically assume that the user stopped the chat when a certain timeout has been reached.
Often, the user isn't aware of the fact that when the app is put to the background, it is unable to maintain the connection to the server and will stop the chat. I'm looking for a method that will notify the user of this behavior as soon as the app is put to the background.
My current idea is to notify the user when applicationWillResignActive and/or applicationDidEnterBackground is fired, but I wouldn't know in what way. Can it be done in a way that complies with Apple's guidelines?
I'm aware of the fact that the best solution would be a different overall design of the software (e.g., using push notifications and no server-side chat termination by timeouts), but in this case I can't change that.
I would continue running in the background and set an expiration handler block (called by the os when you app is REALLY killed) and there schedule a UILocalNotification
use
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler

How long can an iPhone app live in the background?

I can't seem to find a clear answer to this-- I'm spec'ing out an iPhone app that I'd like to have live in the background and notify the user at certain periods throughout the day. So the user would launch the app in the morning and then continue to use their phone, then every few hours the app would pop open a notification dialog.
Will my app ever be shut down (automatically) by the OS? Or will it just live forever, notifying user when it needs to?
thanks,
Eric
Basically there are three kinds of running in the background on iOS 4:
Running in the background to "finish" stuff (e.g. upload a posting or a picture, finish processing something etc.). You ask the OS to grant you extra time after the user switches to another app, and it will tell you how much time you got. You can't run in the background for an indefinite time.
Running in the background to do specific stuff: VoIP, tracking location (e.g. for GPS navigation), or playing audio. You can only do the stuff that you told the OS you would do in the background.
Local notifications (UILocalNotification). From your description, this is what you're looking for. You're not actually running, you just schedule notifications, and when it's time to notify the user, they'll be notified and can go to your app. If you need to notify the user dynamically (i.e. you don't know ahead at what times they need to be notified and it's not location or VoIP triggered), you might want to look into push notifications.
Apple has a good overview here:
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence

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.

Can I use Push Notification for this

My app should post some message to Twitter at the end of each day at the time X. App might not be running at this time X, but it still has to post that message. I don't want to bother user by everyday asking to do this task.
Can I use Push Notification to silently (without any alert view popup, sound or anything else) do some task in my app in some constant time everyday even if it's not running?
thx
There are three 'notification' mechanisms you can send via push: alerts, sounds, and badge values. The way the push notification works is that on the phone it launches the app and hands over the 'push payload' to it with those values. Even if you turn off all three mechanisms, the OS will still have to launch your app each time, which means the user will get interrupted.
In short, you can't have a push happen silently. I doubt, from a user-experience point of view that Apple will allow things to happen on the phone without the user getting notified somehow.
No.
You can't schedule things to be run by your app on a non-jailbroken iPhone.
The only solution is to have a separately hosted service somewhere to which you push details from your app and that runs the scheduled updates on your behalf.
To do so silently is not up to you. The iPhone device has a configuration in which each app with a Push mechanism has settings where one can specify if they want alerts or not. If set to yes, the text of the alert is displayed as well.
sounds like you are trying to "wake up" your app at a specific time each day to perform some type of task. from what i understand about the iPhone this is not possible. you cannot create a cron job or something that will fire on a time you specify. you can run this on the server side and then push a notification to the user telling them that the message has been posted to twitter.
if you are on a jailbroken phone i feel confident that there is some way to do this.
Given that push notification requires that your server send a notification, why not skip a step and have the server just send the update directly to Twitter on the user's behalf? You can't use push notification to trigger an automatic task on the iPhone like you're asking - the user must take the step of accepting the notification for anything to happen.
if you really want to do it from the phone, you can just declare a "long term" background task should be covered around here (iphone app programing guide) some where..., that way you never go sleep, and you can do what ever you like... :)