I have an app which needs to communicate with a server (to refresh it's data) once every 24 hours. This needs to happen even if the app is not open, nor in the background.
Ideally what I'd like is:
Every 24 hours, my server sends a push notification to iPad
This wakes up the app, and runs the code necessary to refresh the data
The notification is then discarded
Is any of this possible?
Is the app only woken up AFTER the user clicks on the notification? Or can I run some code before showing the notification?
Can I even discard the notification message?
If Push notifications are not the right way to do this, what is???
Thanks guys!
With release of iOS 7 this is finally possible using Remote/Silent notifications. They work same as Push notifications but instead of alerting the user immediately they can fire up background fetch mode and upload/download new content.
Here is simple tutorial:http://www.objc.io/issue-5/multitasking.html
This is only possible if your application is a Newsstand App, if it is, you can send a push notification with content-available: true once every 24 hours.
If it is not a newsstand app, you can instead use GPS fences to run code. It is allowed to let the user set up GPS fences if they want the app to update when the user comes close to an area (ie. their home / work). This will wake the app and you can run the background download then. Instapaper for example does this.
if the period is always going to be 24 hours you can use local notifications instead of push notifications.
your app won't be able to run any code unless the user open the push notification, push notifications are handled by the OS and your app have no control on them while it's not active or in the background you should take a look at the push notification programming guide
an alternative way to accomplish what you are trying to do, is to get the data from the server every time the app is started and the last update happened 24 hrs earlier ,
every time you contact the server save the date in NSUserDefault
every time the user opens the app check if the last server contact happened before 24 hours then refresh data
It is possible using a so called VOIP Push Notification. This notification can run code in the background, even when the app is completely closed.
Related
I need opportunity, run some code at the moment when my app is killed. For example, a user doesn't open my app in the course of week or month.
Some information about working my app.
The User can save settings which contain push notification. These local push notification my app can get every day, but time every day can be different and I want to create local push when my app is closed and doesn't open during some days, weeks or months etc.
I have read about "silent push notification", but it is not fit me because in my app hasn't a server. Also, I have read about "significant location", also it is not fit me. Who knows an alternative way, how its implementation?
Since your goal is to run a local notification some number of days after the app is terminated, one solution is to schedule a local notification when the app enters the background. When the app enters the foreground or if it is restarted, check if enough time has passed or not. If not, delete the most recently scheduled local notification. This way it only triggers if the user doesn't actually use your app for those days (or whatever timeframe your choose).
There is no point to use repeating notifications if the scheduled time is variable. There is also definitely no way to run some code in the background if app is killed, so the only suitable solution would be to use remote push notifications. If you don't want to deal with the trouble of making a push server etc. Firebase might be a good choice: Firebase Cloud Messaging client app on iOS
I have an App built on Swift, I want this App to start every day at some particular time. Logically its like Calendar notification, which gives notification in that particular window whatever we set.
Does is the same scenario is possible with an App in iOS Swift.
What you can probably do is to create a local notification, but this is not opening your app. A local notification is just a way to show a notification on your iPhone and then, if the user taps, it's opening your app.
See more here: https://www.codebeaulieu.com/49/How-to-add-local-notifications-to-your-app
I am not sure what you want to do, you cannot force your application upon the user without the user's consent. What you can do is schedule a local notification so the user knows when to open your app like jomafer proposed already. Also possible is to wake up the app to do stuff in the background:
https://developer.apple.com/library/prerelease/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
For example a silent push notification that will trigger some code, or a scheduled background download.
NONE OF THESE METHODS ARE 100% RELIABLE THOUGH!
I need some help for scheduling a Background task at daily basis at specific time in iOS.
I want to call a webservice at a specific time (let's say at 1.00 am ) and download all new data to app.
After searching a lot, I came to know about Notifications and timer to do such things but I have some questions
Suppose I create scheduled job on server which sends a push notification at 1 am to device.
After receiving push notification can my app start automatically (without any user interaction with app icon or push notification)?
What should be happen when at 1 am the device has not an active internet connection or my app does not receive the push notification?
Suppose I create a Timer or a local notification to schedule the download at 1 am - it will call the web service only if my app is running
How do I achieve this?
Please give me any suggestion.
Answer to your question
1- After receiving push notification app will not start automatically until user will himself click on that push notification.
If device will have no internet access then again your notification will not be transferred.
I recommend you that you should go with push notification.you can Schedule
your push notification and when it receives on user device run a webService for successfully receiving of notification which will tell that notification successfully delivered in case if it will not be delivered due to internet problem or something else then you can again schedule notification after 30 minutes again until you will get a success.
there is no other option for achieving this.
Hi i am developing an app that will fetch one qoute from my server everyday and will do a local notification in that app and more when you get inside the app.
I started by implementing Push Notification but then i figured that Local Notifications is what i need.
Official Documentation
For example, applications that depend on servers for messages or data
can poll their servers for incoming items while running in the
background; if a message is ready to view or an update is ready to
download, they can then present a local notification immediately to
inform their users.
The work flow of my app is that i need the app to make a post request to get today's quote and fire a local notification for that (that's the hard part) then when user opens the app i think things are easy.
Th issue here is that that request has to be made while my app is not running.
I'm looking for some help on how to acheive that..
Thanks in advance
Apple introduced in iOS 7 something called Background fetch.
The new Background Fetch capability allows your application to ask to fetch data on a regular basis, so when the user launches or re-opens your application, it can start up with the most current data possible.
You can learn how to implement it here
Another option to consider iOS Silent Push notifications. This will let you update the user database without interacting with him. I'd go with Background fetch, though.
I don't think you can run your app in background unless your app meets one of the background modes specified by apple . If you run your app in background without enabling one of the background modes it may result in app rejection by apple .
Now for your requirement you can simply save the qoute for a particular date from server within local DB once a day whenever user runs the app . By setting local Notification repeat itself at morning everyday you can display qoute of that particular date .
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.