I am writing a UWP app that expect to have updated data from a remote, say a cloud service or a remote station or whatever.
So, I thought an obvious solution would be to write a service that will sync data periodically and UWP app will just show it. I started reading about it and ended up reading this MSDN article about Windows 10 AppService
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service
But after reading the article, I stumble upon this portion as per screenshot below which basically tells that if my app is back-grounded (minimized or covered by another app), then the service will continue running for up to 30 seconds and then stop running. This means after 30 seconds, my background syncing will stop:
How can I make sure that my data is being refreshed when needed even though my app is not in the foreground?
Your background task can only run for 30 seconds for processing information but you can make it so your background task runs ever 15 minutes to check if new information is available using a Time Trigger.
If you want your application to check more frequently you will have to use a Toast Notification that comes from a server, such as Azure Mobile App Service, AWS Simple Notification Service, etc. or you can create your own service using the WNS(windows notification service).
Azure
https://azure.microsoft.com/en-us/services/app-service/mobile/
AWS
https://aws.amazon.com/sns/
Related
I've been trying to learn Flutter by developing an Offline-first application using non-firebase backend API. The problem I am trying to solve derives from the following requirements:
Given User devise is Offline and he creates a record in the app, the record is stored on a local Database and is synced to backend once app is back online
If the app is not in the foreground, user should receive notifications once he is back online, given something changed on BE while he was offline.
Now, the problem is that reading through some packages that Flutter provides like background_fetch, I've stumbled upon the following limitation: "Background Fetch is a very simple plugin which will awaken an app in the background about every 15 minutes, providing a short period of background running-time."
The problem is that testing a similar IOS offline-first app I've noticed that notification comes through the moment internet is back online.
My question is the following: How can I achieve an immediate response/notification from my Flutter app once internet is back online, given that application is not working in the foreground. A fetch once every 15 minutes would work but is obviously is less than ideal, and given there are already apps on App Store/Play market that are notifying me immediately just keeps me awake at night. Is there a way to configure an event listener for connectivity change without relying on the 15 min limitation?
I have UWP app service with TimeTrigger. Every time this trigger fires i'm trying to download some data from the internet.
Is there anyway my service can notify my second UWP UI app about data load success|fail? The only way i've found is to run the second service in UI app thread and call it to send the notification.
The original task is to create an always-running data update checking service and load a data consuming UWP UI app that may or may not be running.
I have developed an application. My application takes feedback from users. When network is not available, then that data is saved in local db. But, once the network is available, it will sync automatically with the central database.
But, I have some problem here. If I save database & send my application to background, once the network is available, it has to automatically do this syncing with the central database. How to do that?
I am using Reachability class to check network availability.
At the present time there is no way to have your app "wake up" when the network becomes available. If the user quit your app without a network connection, you cannot do anything until they voluntarily open your app.
However, you can prompt them to do so using UILocalNotification. If your app is being quit and you have some data waiting to be uploaded, you can schedule a notification to fire in 4 hours (or whatever amount of time makes sense).
If the user opens the app before the notification time and you are able to upload the data, you can cancel the notification and no one will ever know it was scheduled.
If the user does not open the app, the notification will appear, and say something like, "You have data on your phone that you have not uploaded in a while. Connect to the Internet and launch MyAwesomeApp to sync your data."
You cannot do it on iPhone. Your app ceases to exist in a few seconds (once the app moves to the background).
I believe its 5 seconds for all apps, 10 mins for some apps that have requested for more background time.
PS: Unless, you mark your app as a navigation or a music app, which can stay on in the background, theoretically, forever. But I doubt if a feedback app can get approved on the appstore with such permissions.
Keep an additional column in your saved database which marks successful uploading of your data to your server. Set this when the data is written, but not yet uploaded. When it's successfully uploaded, clear the value. You can check this value when your app comes to the foreground, and have it upload any data that hasn't had this column cleared. While your app is running, you can set a timer for an appropriate interval to recheck reachability and if successful, attempt an upload. Only clear your flag when the data is successfully written, and make sure your server doesn't try to process a partial upload (think of someone trying to do this on a subway or train, moving in and out of connectivity).
I have an iPhone application like facebook for iPhone. My application must connect my server and read all message every two hours regularly. I have a thread to read all message but when the application is terminated the thread cannot work. Can the thread run undependently from main delegate or how can I find solution for this problem?
You cannot have your app do stuff in the background. There is an API to finish tasks like uploading a photo but even that will be killed after around 10 minutes.
But the Apple Push Notification Service seems like the most appropriate solution for your problem. Your server notifies the device that there is something new happening and you fetch the actual messages when the user opens the app.
edit: As of iOS 7 Apple implemented a feature where you can schedule running tasks to fetch data in the background. Those tasks are not guaranteed to run at any specific times. See the release notes for iOS 7 and the linked methods below:
Apps that regularly update their content by contacting a server can
register with the system and be launched periodically to retrieve that
content in the background. To register, include the UIBackgroundModes
key with the fetch value in your app’s Info.plist file. Then, when
your app is launched, call the setMinimumBackgroundFetchInterval:
method to determine how often it receives update messages. Finally,
you must also implement the
application:performFetchWithCompletionHandler: method in your app
delegate.
There is no solution.
Apple does not permit applications to run in the background unless they are of a specific type such as location or audio or voip or newstand (your app can continue to run for about 10 minutes after it was active if it uses shouldBeginBackgroundTaskWithExpirationHandler).
There is no workaround, many many other people have wondered how to do the same thing as yourself before, but there is no legitimate way. Your app cannot schedule any sort of periodic call home activity.
The only way your app can run once its gone into a suspended or terminated state is for the user to launch it, either explicitly or in reponse to a local notification or remote push notification.
Is it possible that my iphone application will run in background state and after some time interval it will start another program or application from my iphone.
Suppose, I want to start the camera preview after 10 minute later that will be handled from my iphone. So, my application will run in background state and it will start the camera view after 10 minutes.
Is it possible ???
The only way to start other applications is to use the url schemes exposed by the other app. If it does not expose such scheme, you won't be able to start it.
What about scheduling such thing when you're in the background, you can register for timed local notifications that will show a popup to the user when the time has been elapsed. If the user accepts the popup, your application will get focus and CPU so you can launch also other apps.
There is another option, to get some seconds of CPU in every 10 minutes. It is called VoIP services and you can register for it in the project settings, then it'll call a callback in your app delegate when the OS decides to grant you some CPU.
Study "local notifications" and "url schemes", these are the technologies you need.
Specifically on whether your app can do anything while in the background state, recommend watching the 2010 WWDC video "Session 105 - Adopting Multitasking on iPhone OS, Part 1" : https://developer.apple.com/itunes/?destination=adc.apple.com.4092349126.04109539109.4144345587?i=1907522673
TL;DR: you can only finish up tasks upon entering the background. MrTJ is right about using a timed local notification, and you can also investigate Apple Push Notifications too, if a bit more work and outside the scope of your original ask.