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 .
Related
I am building an iOS application in SWIFT where user location is fetched and sent to the server after every 30 mins. When the app is opened it keeps sending the location lat/long to the server but when the app is closed or suspended it won't send. I want to send the location even the app is closed. Is this somehow possible? I just want to send the location to server no need to open the app again and again?
You app needs to support Background Tasks for being able to run in background.
I believe this has been answered multiple times. Here is the documentation link
Since you are using location, I would recommend you to use UIBackgroundModes as locations.But be sure you don't drain the users battery.
Also usage of background fetch (UIBackgroundModes - fetch) and silent notification can be a great way to get you app running after equal interval of time.
Update
For performing operations you can use silent notification - refer this apple documentation
As per documentation - the system wakes your app in the background and calls the application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
Update 2
For local notification along with scheduling custom action refer this apple documentation. But I really doubt this will help you achieve your desired result. Mainly because you app would get an event only when the user performs any action on your local notification and if he ignores it, you app will remain in background.
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 have 8 medicine local notifications which differ from day to day.
They work fine for one day but I want to fire them everyday. I used BackgroundFetch to reschedule the local notifications every time fetch is executed. But my problem here is that background fetch depends on how often the user uses the app. What if the user doesn't open the app more often Also I didn't want to implement silent notifications because it will not wake up the app if the user does not have internet connection. what approach should I use instead of background fetch?
EDIT:
I also thought about location updates in background because my notification times are taken from location of user and calculated accordingly. But will this consume a lot of battery?
Since I've got the same issue in an
app that probably does the same stuff as yours, I'd like to share my solution.
It comes with one compromise works only from >=iOS8.
By using an interactive notifications you can reschedule your notifications in background, of course the user need to interact with the notification, but I think that if you different actions instead of open the app or cancel the notification is possible to have more interested user.
It's all about creating a configuration with actions.
Here you can find a tutorial.
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.