A couple days ago I shared with a friend my code to quickly and easily do reachability checks in RubyMotion, and I figured I would post the code on my blog as well. In addition to detecting network reachability, this code suspends the operation queue when the target host is unreachable, allowing you to continue appending requests and ensuring that they will be delivered in the order they were queued.
There might be a more efficient way to do something similar, but this works for me.
Rakefile
Add the really awesome Reachability Pod to your project.
1 2 3 4 5 6 7 |
|
AFNetworking AFHTTPClient Subclass
I also use the super convenient AFNetworking library to quickly and easily do REST-compliant requests to my servers. This is the code I stick in my AFHTTPClient:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
app_delegate.rb
Finally, call the setupReachability method in your app delegate and you’re done:
1 2 3 4 5 6 7 8 9 |
|