I have a method which is called, and the first thing it does is ascertain when the network is reachable. If it's not, I'd like to wait 10s, then run the same method with the arguments/params that were initially passed in..
This is my disastrous attempt (I'm more a JS dev, relatively new to Objective-C):
- (void)sendRequestToURL:(NSString *)url withPostData:(NSString *)postData withPage:(int)page sortBy:(NSString *)sort completionBlock:(void (^)(NSDictionary *))completion {
if(![FooNetworkManager isReachable]){
self.lastRequest = ??? // lastRequest is an NSDictionary
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 10);
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
[self sendRequestToURL:self.lastRequest]; // this is almost definitely wrong
});
}
}
In JavaScript, inside a method we have access to the arguments
object that contains all the params that were passed into the method, not sure how to replicate this in Objective-C.
Also, self.lastRequest
is defined further up in this same class:
@property(nonatomic, strong) NSDictionary *lastRequest;