简体   繁体   中英

IOS background application can use library to download resources periodic?

I am working a cocoa touch static library for the applications, and the library has a feature to download network resources by NSOperation in the period time, and provide some methods.

I knew the IOS applications enter the background has limited,(like 5 seconds in main thread, 10 min to long task...) So I want to know IF some application used my library entered in the background, My Library's period download task will be terminated or alive? And the application also used my library's function successfully?

Think of moving into the background as having your app 'freeze dried" - all state is frozen at that moment. When your app moves to the foreground, then the app starts running using the now somewhat dated information. NSTimers etc will continue to work but the "gap" between the last firing and the next firing will be huge. [I believe (but don't recall for sure) that if you had had a timer set for 2 min, and you went into the background with 1 min remaining for say 10 min, that when you move to the foreground the timer will fire immediately].

What I ended up doing was keeping a NSDate object that had the time of the last firing - so I could detect large gaps due to getting moved into the background - and taking appropriate action.

Note that web fetches etc that were in process should just return a timed out status - but again, if you keep a NSDate around of the time you initiated the fetch, you can detect this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM