rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

Background execution with scheduler and http #257

Closed stevebooks closed 11 years ago

stevebooks commented 11 years ago

If I am preforming a scheduler or HTTP operation and the user clicks the home button (thus sending my app into the background), will the HTTP / scheduler request finish?

I know iOS has a "dispatch_async" method that requests additional time from the processor, is something like this used in Bubblewrap?

clayallsopp commented 11 years ago

Looking over the code, it does not appear BW does anything of that sort - if your app backgrounds, it's up to you to manage what happens.

You can get a request's NSURLConnection using something like my_nsurl_connection = BW::HTTP.get("hello") .... Then you can either handle an interruption or request more time via other Cocoa APIs (see http://stackoverflow.com/a/9164755).

It would be cool if this were incorporated into BW's API somehow, would love a PR for it :)

stevebooks commented 11 years ago

So currently, if the app is put into the background, would it still call the |response| block (with an error), or would it not call the block at all?

I would assume the latter.

clayallsopp commented 11 years ago

Yup, you would get no callback if the app is put into the background and, more precisely, killed/removed from memory before the request finishes. (IIRC there's about a 5-second window where your app appears in the background but is still technically in memory.)