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.
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 am using FCM to send iOS push notifications for an app that is used worldwide. Different users are in different time zones.
Is there a way to specify ,that when delivered at worktime local time Mon-Fri (8:00 - 17:00) it will have sound, but any other it will be without sound. I do not want to disturb the user at night.
This question is mostly about the worst situation when my app isn't running/backgrounded/suspended (for example after reboot) and/or offline
.My app uses background fetch, but that doesn't guarantee that it will be running at the delivery time of the push notification.
The problem is i do not know in advance when the push notification will be delivered. If i knew i would specify the sound key in the JSON.
The user could be offline when the push notification is sent.
For example, i send the push notification at night without sound, but the user enables internet connection at day and receives the notification without sound (because it was sent in the night)
Scheduling the sending time at the server won't solve this, because we cannot control the delivery time.
If it is possible using directly APNS without Firebase then that would also solve my problem.
Thank you very much.
Clarification:
When my app is running i have enough control to decide according to local time if the sound should be played. The question is aimed at the other case when my app isn't running/backgrounded/suspended.
I am using silent data notifications (JSON key data with content-available=1) to deliver all neccessary info, but when my app is not running there is only one way to send a notification that will be shown - that is a Display notification (JSON key notification)
It is widely known that:
app doesn't receive push notification if it is in background or offline mode (app gets it once after user's action: tap on notification or app icon).
Apple push Notification service keep only ONE last notification when device is offline. Once device is connected to internet, APNs sends the last notification.
How to solve this?
very latest notification that just reached the app (not device) must reflect the actual number of notifications that are not implemented in the app yet. So, then I can download from the server last n notifications and implement them in the app at any time.
The question is:
How the server knows what notifications were implemented in the app, and which one not?
Notifications must be per device. Why? For instance, notification "remove object from Core Data" must be implemented in every device. Because only one user can be logged in on multiply devices at time.
You should track the state of the task (delete record or whatever your app needs to do) on the server and have the client report back when the task is done. Then flag the task as done.
Don't use push notifications as a reliable delivery method for your tasks, you will fail. Use the notifications as complementary part of your setup.
So for example when your app receives a notification, it can sync with the backend, to retrieve the tasks flagged as not done, execute them and then let the backend know that it's done.
I want to develop an app regarding push notification.
I want to send a push notification to 5 persons who has installed my app and are stored in my directory.
Can I send Push Notification to 5 people using their UDID which I received from each and every person who has installed App. (As UDID is banned)
I want to send them continuously to 5 persons till one does not press OK button on Alert?
Which service should I use for Push Notification?
Is push notification receives on time or it delays?
You cant send the push notification using UDID, you can use the Apple service for sending the push notifications via device-token and pem file which is explained in below link.
http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Any push notification that isn't delivered immediately was queued for future redelivery because your device was not connected to the service. "Immediately" of course needs to take latency for your connection into account. Outlying cases would be beyond 60 seconds as APNs will time out at that point.
Still you have any query then you can refer the below link http://developer.apple.com/library/ios/#technotes/tn2265/_index.html
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.