Back to iOS application automatically when it's suspending in background. - ios

I have a question,
I work on a Swift 3 project with Xcode.
My goal is to send an alert sms, 20 secondes after receiving a local notification. when I'm in application, every things work well, but when my app is in background, it can do other tasks, like print some character, or play music, or send a text to a socket server, but it can't send the sms.
I think, when I receive an alert, if I could back to my application automatically, then I can send an alert sms, that's why I'm doing this stupide idea and looking for a way to know how I can wake up automatically my application and go back to the first View Controller Screen when I receive a Local Notification?
Maybe there is someone who knows a method to return to the iOS application automatically?

When your app is launched into the background—usually to handle some type of background event—the launch cycle changes slightly as given in the picture below. The main difference is that instead of your app being made active, it enters the background state to handle the event and may be suspended at some point after that. When launching into the background, the system still loads your app’s user interface files but it does not display the app’s window.
Reference - https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html

Bringing your app from background to foreground is not possible. And even if you are able to do so, App store will reject it.
Hope it helps!

Related

Keep program running in background ios

I am working on an application which allows to send messages to another user.
If I press Home Button app goes first in background and then in suspended state so I don't receive any message unless I bring app back to the foreground.
How can I fix this to receive messages even if app is in background or suspended state? Solution is to avoid app to go suspended?
Some ideas please
Thanks and regards
For that you have to use Push notifications as they will wake your app when a notification is received (in your case a message is sent to your app). Do you have this implemented?
Another Dirty way would be to keep a silent Music file playing when in background state thus the app nevel sleeps (unless terminated by user). Nut keep in mind that this trick wont let you publish your app to the app store!
Hope this helps!
Use Voip to wake the app upon receiving push notification then handle it and pull from server as you want
migrate-to-ios-voip-push-notifications

Run Services when application is suspended and get notifications and open specific screen

I am working on application in which I want to run the background service after every 12 hours even the application is suspended or any state just like Facebook. And in that service, it will hit the webService and get the data. And when the data is changed after 12 hours, I will get the notification that this item is added, and when I tap that notification, i will move to the specific screen.
I have read on many forums that when the application is in background state, it will take only 3-4 minutes to terminate the app, and after that time, no event will occur.
But I have seen on Facebook, WhatsApp or any other social media app, even the app is in not running, or in suspended state, the app still gets the notification.
Please guide me what should I do.
This is not how it works.
The notifications you see from Facebook or WhatsApp apps are Push Notifications.
The app is not fetching information from the server. It's the server that "pushes" information to your user's phone.
Push notifications don't require your app to be active to work. And tapping on them will start your app and show the correct screen if handled correctly.
For running a task periodically, you can look into Background Fetch.
This works great, but iOS decides when to call it and can completely stop calling it (if the phone is on power saving or if your app is manually killed for example).
Keep in mind that in iOS, there is NO WAY to force the device to execute code if your app is suspended/killed. You might want to review your workflow.

how it works whatsapp

How does Whatsapp continue to receive notifications of received messages, even after you kill the app or restart the phone?
I am using an application that sends location coordinates, and it's for iOS, written in Swift.
My problem is that when I kill the app, the application stops sending coordinates. How I can make it restart automatically? For example, Whastapp, despite killing the app, if someone sends me a message, I receive the notification
I have also tried creating a widget app, but this is activated only when under the bar where the widget exists.
WhatsApp continues receiving PushNotifications. These are sent by Web Server and the App need not be active for it.
Coming to your requirement, you can use options like requestAlwaysAuthorization (to keep App awake in background to be able to send notifications). SignificantLocationChange, RegionMonitoringService, VisitService (to relaunch you app in the background if terminated).
Hope it helps.
Use this tutorial https://www.raywenderlich.com/123862/push-notifications-tutorial. you need to have one developer account to use push notification. It's easy to implement.

iOS display message on lockscreen

One of our clients asked for this functionality: "Permanently display a message (or image) on the iPhone lockscreen".
Our initial ideas were:
Changing the device lockscreen image:
Couldn't find a solution for doing this. Couldn't find even a private API for it.
Playing an audio in background and display an album artwork. It has a few problems:
We cannot hide the volume and track buttons
Display a notification:
The notification will go away after the user skips the lockscreen
Any ideea how we can accomplish this request. Please note that the app is NOT intended to be distributed via AppStore. This is an internal app only. It should work on NON-Jailbreak devices through. The app will be enterprise distribuited.
Kind regards,
Artwork
If it's not intended for the app store, you could definitely use the artwork thing. Since you don't need to comply with the iOS guidelines, just warn your users that the lockscreen buttons won't work if you try using them. This link and this one should help.
Using the iOS 7 background fetch can help you manage messages display, as long as the app has already been opened once. To know if the app is opened, you can send ping to your server saving the current app state every X minutes. If the server doesn't receive an update, it will just guess that the app is not running, he'll send emails or push notifications to the user until he does so.
Issues:
If the user opens an app like Music or any other that can become a responder, it will override your message.
You can only display a message if the app is opened at least once.
Remote notifications
It could be a good option since a notification can stay on the lockscreen as long as the user or you doesn't clear the notification center (you have to set it). And you can remotely display any message without the app being launched.
Issues:
You have no way of knowing if he cleared the notification. An idea would be to send them an email if notifications have been disabled.
Users can just disable notifications.
Lockscreen image
You won't be able to change the device lockscreen image without a jailbroken device.
I'd go with the first one, if it's a client requirement it seems like a reliable one. It all depends on how much control they have on the devices.

waking up ios applications without using ios notification

Is it possible to wake up a background application with a non ios notification center? e.g. if I were creating a calling or messaging application is it possible to wake the application via SMS.
Nope. If you want to call app outside the device, you should use APNS. On the device you can use local notification. Sending SMS to wake up app is kinda wrong. People don't like such solutions - imagine bunch of SMS every day for different apps. Sorry.
No.
If you have background code running, you can schedule a local notification to yourself. If the user clicks "Ok" then you will come to the foreground. See here for a description and sample code.
As far as I can tell, the only ways to launch an app without user input is via a custom URL handler or via an accessory. It doesn't sound like an accessory fits your use case. Sadly you can't open URLs from the background, so you can't use this to wake yourself.

Resources