AnswerMe
AnswerMe

Reputation: 189

How to create background services for local notification?

I am trying to create local notifications for my iOS application based on JSON new data.

I have created web services and parsing some datas and store into plist as a string at first time. I want to parse JSON at every n minutes once and compare with plist stored data for anything newly arrived datas or not. If anything newly arrived I want to show notification.

Those process want to do application active and background both times without any hanging.

Thanks,

Upvotes: 0

Views: 589

Answers (3)

Mukesh
Mukesh

Reputation: 3690

You can use Silent Push Notifications,if Push notification serve your purpose.It doesn't come in notification tray.

1.As soon as when notification comes , Below method is called,overide this method

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
  completionHandler(UIBackgroundFetchResult.NewData)
    NSLog("Download From Remote Notification%@",userInfo)
}

enter image description here

2.Enable Remote notification

No user Interaction is needed in silent push notification

Here is good article which explains step by step guide

http://www.g8production.com/post/72656082173/ios7-multitasking-silent-notifications

Upvotes: 0

Daniel Rinser
Daniel Rinser

Reputation: 8855

If you want to update data from the server in the background, you basically have 2 options:

  • Use background fetch. The system will launch your app into the background in specific intervals (which are not entirely under your control!) and give it the chance to download (have a look at this post for a good intro).
  • Use (silent) push notifications. This of course requires work on the backend-side.

Which one you should use depends on things like

  • Whether you have control over the backend (if not, you can't send push notifications)
  • How often the data is updated. If it's updated very often, background fetch might be ok. If it's updated very infrequently or irregularly, then push might be superior.

Upvotes: 1

rckoenes
rckoenes

Reputation: 69489

iOS does not support these kind of background service. The reason being that they drain the battery and therefor give the user a bad experience. You might want to implement it serverside.

Apple only allows background running for apps that fall the in following categories: VOIP, audio streaming, location and accessory (bluetooth).

Upvotes: 2

Related Questions