-1

6 months ago I wanted to wake my app for 30 sec from background (terminated app) to download few lines of XML and parse it, but after trying with background fetch and silent push and reading articles online I came to conclusion that what I'm trying to accomplish is not possible.

Until I found Yahoo Weather app, which allows the user to set the time of day when he/she wants to get notifications about tomorrow's weather; notifications are local, and data is downloaded in background every day. How did Yahoo manage to do that?

AstroCB
  • 12,337
  • 20
  • 57
  • 73
opengl
  • 141
  • 1
  • 5
  • 15
  • Terminated and backgrounded are not the same thing. But what you want is possible for backgrounded apps by using the tools you mentioned... background fetch and silent push. You may be doing something wrong in the implementation. – QED Feb 24 '15 at 23:44
  • Yes I know that, and I'm talking about terminated app. – opengl Feb 25 '15 at 00:04
  • If the user has killed your app using the process switcher (double-press Home key and swipe up) then your app process is killed and Apple will not launch it to receive pushes. Is that what you mean? – QED Feb 25 '15 at 00:17
  • Yes, but Yahoo still manages to start app in background. – opengl Feb 25 '15 at 14:11

2 Answers2

2

I can't see their code so I can't tell you exactly how they did, I can however tell you how I have implemented something similar.

You can ask the system to start the application in the background when it has the resources to do so. This is called background app refresh, you can look it up.

When your application is spun up in the background because of a background app refresh, you can download the data that you need to and then reschedule a new local notification each time this happens. This means that when the user actually receives the notification, it will hold the most up to date data possible.

In terms of the weather app. Their app gets updated in the background several times a day and is able to fetch current weather data. They schedule the notification each time and when you actually get the notification, it has the most up to date data.

Kris Gellci
  • 9,539
  • 6
  • 40
  • 47
  • This is all fine when app is in background, but Yahoo app works even when app is terminated. – opengl Feb 25 '15 at 00:03
  • If Yahoo can do this despite Apple's published rules, then Yahoo has a contract with Apple, which is something that you probably won't get. – QED Feb 25 '15 at 00:36
  • @Ty096 You can terminate the app, the point is the system can restart it for a small period of time like to gather some data. Read about background app refresh. – Kris Gellci Feb 25 '15 at 00:57
  • I read articles about background refresh (6 months ago, and again today) and it came to background fetch, and silent push. But neither background fetch, or silent push work when app is terminated by user. You can feel silent push (vibration) but app wont process it (when it's terminated). But Yahoo still managed to do it. – opengl Feb 25 '15 at 14:15
  • Per Apples docs - "The app requires new content from the network on a regular basis. When it is convenient to do so, the system launches or resumes the app in the background and gives it a small amount of time to download any new content. This value is supported in iOS 7.0 and later." Basically, if implemented correctly it does just what the weather app does. – Kris Gellci Feb 25 '15 at 18:11
  • I read that and I tryed that, and it worked when app was in background(not terminated), but when app is terminated it won't run fetch. By Apple Engineer on Developer Forum. `Also keep in mind that if you kill your app from the app switcher (i.e. swiping up to kill the app) then the OS will never relaunch the app regardless of push notification or background fetch. In this case the user has to manually relaunch the app once and then from that point forward the background activities will be invoked.` [link](https://devforums.apple.com/message/873265#873265) Yahoo still managed to do that – opengl Feb 25 '15 at 18:20
0

After some time I figure it out. The app doesn't use background fetch or silent push either, because they won't run if user terminates the app. App is tracking users location 24h and after location is updated the localnotification will download data and it'll be scheduled.

Read more: Will iOS wake up the terminated app if it's registered with location for UIBackgroundModes?

and

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

Community
  • 1
  • 1
Tuc3k
  • 1,032
  • 9
  • 12