Terminated App on IOS 7 and Multitasking - ios

is it possible to have the App Connection to a server Open even if the App has been Terminated from the Background ?
Here is what I'm trying to accomplish
Twitter Client should keep watching user events . and when that events occur it send a Local notification to the user . the whole idea is to stay a way from Push notification and all servers Problems and costs
so in order to to get Local notification works just like Push notification the connection between my IOS 7 App and Twitter API must be Open all the time
any idea if that even possible ?

No, this is not possible. What you're basically asking for is a daemon functionality which is not available on iOS. The whole point about iOS multitasking is that the OS can (and will) terminate your app if it is in the background and other tasks need the resources. That's the problem Push Notifications solve (to some degree).

You could possibly try background fetch feature on iOS 7 to periodically download content updates for user in background.

Related

Xamarin iOS App is not able to execute code when it is already minimized

I have a chat application, developed on the Xamarin.Forms platform, in which users can chat with each other. I have managed c# code and UI both in the shared project.
I have been facing problem since long in iOS platform. When the iOS app is running on screen, having foreground mode then the app can successfully receive a message which has been send by another user. When the app is running in the background mode and someone sends a message, I want to notify the user by using local notification (No Push remote notification - Because I think as my app is already running in minimized mode there is no need to wake up the app by implementing Push notification). Even I have implemented local notification successfully but the problem is,
When the iOS application heads to the background mode, the main thread (task) is paused so, when some user sends a message the app is not able to execute the code (when app is minimized) so that it won’t be able to show the local notification. But when the application is brought back to the foreground the thread/task get resumed and then ie shows up the local notification and also the message.
I already have selected the "Background fetch" property under Background Modes in Info.plist. I have also added below the line in my FinishedLaunching method
UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
I have already worked and implemented code from below links, but didn’t worked for me.
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/ios-backgrounding-with-tasks#performing-tasks-during-didenterbackground
Xamarin forms background tasks run only when app is open on ios
https://arteksoftware.com/backgrounding-with-xamarin-forms/
When an iOS application goes to the background, are lengthy tasks paused?
How to perform a simple background task on Xamarin iOS
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/ios-backgrounding-with-tasks#creating-background-safe-tasks
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/
I think my issue is relate to iOS Background processing, So, does anyone has idea what to do, to execute the code when app is already in minimized mode?
Generally speaking, backgrounding is very restricted on iOS. If your app is in a certain category (e.g. Navigation, Music) you'd get extended backgrounding capabilities, but I don't believe that chat apps do. More specifically, Background Fetch is not really suitable for your problem. It is called on an irregular basis to fetch contents to be cached within your app in order to make showing contents to your users faster. Background fetch intervals may vary from 15 min to several hours (not sure about the latter).
What you need is remote notifications.
Remote notifications (also known as push notifications) let you push small amounts of data to devices on which your app is installed, even when your app isn't running.
Remote notifications are brokered via a priviliged service (Apple Push Notification service - APNs) to Apple devices and delivered in a timely manner (seconds rather than minutes or hours). Usually you'd want to keep the payload as little as possible (just send the chat ID for example) and let the app fetch its data when it's notified.
Speaking in terms of a chat application, your chat server would send the remote notification to the APNs whenever a user sends a message to the chat. The app would be notified, fetch additional data and then display the notification to the user. If the notification is tapped, the user would be taken to the chat window for the respective chat.
Please note that your app has to be registered with APNs, otherwise remote notifications won't work.

React Native iOS send notification through receiving socket.io from the server in background mode

I am using react-native-notification module to send a local notification when I receive a socket.io event sent from the server. The notification is properly configured and works on both iOS and Android in foreground mode. However, due to the fact that Apple doesn't allow Apps to run on the background except for (Audio, navigation map, etc.), I am not able to receive any socket events when my app is not on the background and temporarily suspended.
I'm therefore not able to send a local notification to the iOS device since the app isn't really running once I switch the app to background.
Here I'm asking for possible solutions to my current problem.
This could be a general question regarding react native or iOS native.
Everything works well on Android devices and I don't think there is anything wrong with my code so I don't know what code I should display here.
In short, I just want to know how to receive socket events when the app is in the background on an iOS device, or if that can't be achieved. I would like to know how most apps even send notifications to their users when their apps are in the background.(I do not want to cheat the system and set the background mode to audio).
I know its a old post but if anyone still wondering, You can send notification even your app is closed or socket disconnected. You can use firebase push notification which will handle your current situation even if your app is killed.
Try below plugin to send notification to both android/ios without using any background service react-native-firebase

What is the best way to keep updated the info of an iOS App?

Since push notifications may not be delivered sometimes (you can lose a few of them), you can not run code after the iPhone is turned on to check if there is new information available from the server, and you can not run code if your iOS App is closed... What can you do if you want to be as more accurate as possible in for example a Chat App in iOS?
I mean, inform the user as faster as possible that he has new info available. Comparisons: WhatsApp is updated without any delay.
You can do background fetch if your App is in background. But if the App is closed and you miss a push, it's not going to be up to date until the next push arrives or user opens the App. The same with silent notifications. If the app is terminated by the user, you are not going to receive it. Is there any way to solve it? It must be because other Apps do it... If there is any "private and secret" API that they are using (I read about this answer when no one know how to do that)... Is there any way to apply to use it?
UPDATE:
I'm using push notifications. The goal is to fix when a push doesn't arrive. Example: User A send chat message to user B. User B doesn't have the App open. The system lose the push. User B is not going to receive the message until he open the App.
Push notifications seems to be your only way even if you do loose a few of them, which I don't know how you would since they are pushed to apples secure server... but what do I know. As long as the user turns on the push notifications you should be fine. They may be delayed due to apples way of handling them. Honestly push seems to be the future, having your app constantly every minute or two check for new messages is a huge battery water in conjunction with normal texting apps. Your app should provide the best live data but since apple restricts to push notifications when the app is off or not running just stick to push notifications and only push major events to the user. I believe you can set up a job scheduler using quartz or schedulator to setup your server to push notifications to your app.

Is there any way for an iOS app to retrieve updates or make a web service call while not running?

I am developing an iOS 7+ app and was wondering if there was a way for an app that wasn't running (i.e. not running in the background but completely killed) to start running and perform a function such as a web service call. I am aware of mechanisms such as background fetch and core location being able to send events to an app while in the background (but still running/suspended). Is there such a way to send events to an app that is not running?
I know the answer is probably no, but I need to confirm it.
Unfortunately NO.
Background Fetches will only work after the iOS starts and will stop working once the user force-closes the application. The same is true for Silent Push notifications and Location services.
This SO answer explains the details.

Check database every 12 hours in ios app

In my app, I want to check my database every 12 hours for an entry and if found, set a notification.In android,it is accomplished by using a service.But in ios services are not allowed.I tried to implement NSTimer,but it will be reset when the app goes to background.I want my service to be run when the app is on background. On research the only possible way I found is to use push notification.But if the network is disconnected,push notification will not work and notification will not be set that day.Is there any other possible way to implement my requirement please?
Long-running background processes are only allowed for VOIP applications that need to maintain an open connection to a server.
Push notifications are not guaranteed to be delivered, however, if your server sends your iOS device a push notification, the notification will be queued at the APNS server residing at Apple. When the target device is reconnected to APNS, the notification will be delivered.
The only way you can check the database is when your app is running. You can't do it when your app is on background.
Only VOIP, Music and Location based applications can run on background for long durations.
You can use UILocalNotification to alert the user to open your app.

Resources