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.
Related
I have an application which has communication with a remote server. The server should push data into it using remote notification silently, and I need to get and store these data into a CoreData database. The user won't be aware of the whole process.
I can successfully get notified when the app receives a remote notification, while it is either in the foreground or background mode. However, I need to get data while the app is terminated as well.
I searched for the possible solutions. For example, this SO question was good if I don't tend to use silent notification. I also saw the PushKit capability, but I am not sure about the Apple Review result.
What is the possible solution?
If I want to use VoIP and PushKit to get notified when the app is terminated, would Apple reject my application?
If you’re not creating a VoIP app and you want your app to be in the App Store then the correct answer is: it is not possible. The only thing that can be done is adjusting your requirements in some way.
For instance you can send some notifications that will be visible for user in the Notification Center and wait until the user taps the notification or starts the app the usual way. Then the app will be able to do all the operations you need.
The delivery of push notifications is not guaranteed, so you should not rely on them to synchronise data.
For example, if multiple push notifications are sent while the device is offline, only the last notification is delivered when the device comes back online; the earlier notifications are lost.
When your app launches one of the first things it should do is check with your server for new data.
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 have the task.
My iOS app must send heartbeat messages to the server once for every 10 minutes.
iOS app must do this always when the app is not killed (i.e. terminated i.e. removed from task manager) despite the screen is locked, the app in the background.
I'm trying to do this using "background location". But if I use CLLocationUpdate in its' usual mode - I get my battery drained.
Could you help me?
You are out of luck, this is not possible on iOS. Yes you can use the location manager, but if I set a my desk for an hour your app will not get a location update.
Also it is misusing the background location mode and might get your app rejected.
An option can be to use silent push notification, you server will send a silent push to the device where the device will respond to it in the background.
Read more about
application:didReceiveRemoteNotification:fetchCompletionHandler: and the Local and Remote Notification Programming Guide.
is it possible to have the App Connection to a server Open even if the App has been Terminated from the Background ?
Here is what I'm trying to accomplish
Twitter Client should keep watching user events . and when that events occur it send a Local notification to the user . the whole idea is to stay a way from Push notification and all servers Problems and costs
so in order to to get Local notification works just like Push notification the connection between my IOS 7 App and Twitter API must be Open all the time
any idea if that even possible ?
No, this is not possible. What you're basically asking for is a daemon functionality which is not available on iOS. The whole point about iOS multitasking is that the OS can (and will) terminate your app if it is in the background and other tasks need the resources. That's the problem Push Notifications solve (to some degree).
You could possibly try background fetch feature on iOS 7 to periodically download content updates for user in background.
I see iOS applications like Facebook that send notifications even if the application hasn't been launched.
I need to schedule a task with a timer that gets executed at every time interval, and this task (should be inside the same application) should deliver a NSUserNotification if meets some conditions.
How can you set up such a notification even if the application isn't running?
Facebook app and other apps that send notifications when they were not launched do this by using the remote notification mechanism.
To use this, you need to setup a server, create push certificates and use a APNS library for your preferred server.
Take a look here for details: http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
Scheduled notifications can be done with local notifications, using UILocalNotification. However, like push notifications, local notifications cannot run code. They present a notification to the user, who may or may not choose to start your app in response.
If you want to run code in your app on a timed schedule, then your app has to run in the background. And Apple limits background apps to only a few specific purposes. If your app doesn't fall in one of those categories your app can't run in the background (see UIBackgroundModes key).
Significant location change monitoring can start you app when a location change has occurred but that is location based not time based and cannot be scheduled.
It cannot be done in the way you think, you (like Facebook) should use Apple Push Notification Service.