I hope that someone could help me to find the better solution that fit my problem.
The scenario is the following: My app should periodically connect in background to some third-party end point and fetch some data. If there is something interesting the app should present a notification, so the user can open the app and see what is interesting.
I've already done in Android with Worker API. On boot, or when the app is launched for the first time, I create a periodically work (each 30min) that connect to the end-point, download data and show a notification, if any.
On iOS what should I do? First of all, there is no bootup/startup listener. Background fetch as I understand don't suit my problem, because reboot or app kill. So I'm not able to find the right solution of my problem, the last chance is to use push notifications:
In this case I should have a server (maybe a PHP hosting with Cron Jobs) that periodically send a push notification to all my clients (maybe with firebase or iOS SDK, what's the better solution?), when the app receive that "push", should connect to the end-point, download some data, and present a user notification only if any.
Is this possible? Is there some examples? I'm sorry if the question was already asked but answers are very old and I need to know if nowadays there is a better solution to my problem.
EDIT
Thanks to anyone who participated in the comments but #Paulw11 has right. No way to be guaranteed that the app will do the background work. So, the only solution is to do everything in my backend.
Users must Sign In to the app, register on my remote database which endpoint they would follow and use Cron Job (or something like that) to send simple push notifications. I'm very disappointed.. Anyway I'm still open to other suggestions, if someone would answer to my question
Related
I want to run some code everyday at 9 AM and 5 PM on iOS.
This should not be depend on application state; whatever state it has, the code must run at a given time, even in background and suspended states.
Please suggest a solution.
There are multiple ways to run the app in background and one of them which i'd believe you want is for network access, apple gives you some time to finish the request and update the UI, even if the app is closed. The user should grant access for you to do that, but is also questionable if apple will accept it if you don't do a network request and use it for something else.
Another solution would be silent push notifications, in theory the app should be awaken to execute it without asking the user anything, but you need a server and a network.
You'll want to take a look at "local notifications" in iOS. Most documentation you'll find online will talk about UILocalNotification (like for example this nice tutorial here https://www.appcoda.com/ios-programming-local-notification-tutorial/), but if you're developing an iOS 10 app you need to look at the new UNNotificationRequest class instead because UILocalNotification is deprecated in iOS 10. Have a look at the docs from Apple here: https://developer.apple.com/reference/usernotifications/unnotificationrequest
I hope this sends you in the right direction :)
I am looking for a good way how to make my app "upToDate". These are my requirements:
I have an RESTful Webservice, with tasks for different users. Every user has an iOS App, which should get automatically updated when the Server/Service assigned a task to that User.
So first ill created a manuall "Sync" Button, which checks for new Tasks. Fetches the data with Alamofire, and updated the UI.
But, my goal is automatically sync if there are new tasks.
So, ill guess there are 2 different ways to solve that:
1. Make a Background Fetch (with a NStimer?) every xx Minutes and check if there are new tasks.
After checking that tutorial here:
http://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial i am not sure if a background fetch is a good way to solve that. In that case the App uses an scheduler, to check once for new updates, and not every xx minutes.
So in my case i would create an NStimer in the AppDelegate (maybe in applicationDidEnterBackground) and check every xx minutes for new data (but when there are 3 days not any new task, that would be unnecessary battery consumption, or?)
2. Using Push Notifications.
My other idea is to use Push Notifications, so when there is a new task, ill send a Push Notification an manually start the sync. In my opinion that would use less battery, because he will only start the sync when there is a new task available.
Generaly Questions about using Background Services
So ok, if the user finished the task, some data should be automatically uploaded to the server. Normally not a problem, with the manual sync ill check if there is something to upload. But, what if, when there is no internet connection (ill check if before uploading) - and the user do not press on "manual sync".
So i would prefer to check in my "Background Service" if ill got an Internet connection, and if yes - start uploading some data.
Ill know this is not a specific question, but ill think there are lots of users who have the same requirements and it would be great if someone can help me out whats the best way to solve that in the best and practical way.
Thanks in advance!
Background updates sound wonderful until you realise that Apple throttles them heavily: you can ask to be updated as frequently as possible, but iOS decides what that value actually means based on how often users open your app and when they do so. Apple considers background updates the kind of thing that should happen just before a user opens your app so the latest content is right there, rather than something that runs proactively in the background.
Your push notification solution is a better one, particularly if you use CloudKit to subscribe to record change events using CKSubscription and CKNotificationInfo. If you do this you'll automatically get push messages in your app, so you can get what you want with very little work. You can read my tutorial for more information on subscribing to CloudKit to get push messages.
I have an app that needs to update every time a java web application creates more data. Simple enough, right?
But I found out that my app can`t run in background to ask for more data periodically, and I think I need to use the push notification system. That seems to be overly complicated for a really small thing.
And then, reading about it, I found out that the push notification can never arrive! For example, if the app is offline when the push notification is sent but is online a few moments later.
So, in that case, how can I update the data? I only bring data from the server when the user logs in. I didn't want to do that every time the application became active...
I guess there is a simple solution but this is my first app, any help would be appreciated.
You see why you should read your question before posting it?
And then, reading about it, I found out that the push notification can
never arrive! For example, if the app is offline.
So, in that case, how can I update the data?
Guess what, if you are offline, there is not much you can do... Moving on to serious things:
iOS7 allows you to do periodic background fetchs (check the Multitasking Enhancements). Have this tutorial.
I'm trying to look for a way as to how I can notify a user of new updates based off of a .Net API that I created. Much like that notification you get on facebook, I just need to alert the user that something has been updated. So I'm thinking I need a function that runs in the background while my user uses the app combined with a NSTimer.
Based on my research (and on this question https://stackoverflow.com/a/14835300/639713) apparently you can only achieve such a thing for VOIP and location services. And that using push notification is the only way. Is it really the only option that I can use for such a need? Or are there any other ways?
Thank you for your time.
You have two options:
While your app is open, poll the server every so often to see if there are any updates to report.
This will work only as long as the user has your app open, and as you note, your app will only be allowed to stay open for a long time if it happens to be a VOIP or navigation app.
Use push notifications to push updates to the user’s device.
The disadvantage here is that you will need to write some server-side code to talk to Apple’s push notification servers (as described in this tutorial). This may or may not be a big deal in your particular situation, but it’s the only way to get data to the user when your app isn’t open.
I Googled around and I can't find many discussions on this. I want to develop an iOS program that would use access a REST service, and I want to get notified of updates so I am thinking of long polling. Does RestKit deal with this?
Another questions is what if I want to run in the background? It seems like the proper way to do is to set up an Push Notification Service and notify the user to open the app to receive the latest message?
Doing a job in background is only possible with special APIs like Music and Location, so you won't even be able to do queries if the user is not using your app.
Instead, you should do all the heavy work on a web service, and setup an APNS server to notify the user when something happens. That way, it won't drain all the battery of your users and use technology in place exactly for that purpose.
There's also a lot of service to send out push notifications, if you don't want all the heavy setup. Take a look at http://parse.com or http://urbanairship.com/.