Best way to implement RKReachabilityObserver in RestKit Best way to implement RKReachabilityObserver in RestKit xcode xcode

Best way to implement RKReachabilityObserver in RestKit


The [RKClient sharedClient] singleton already has a property for that (reachabilityObserver). Feel free to use that one.

if ([[[RKClient sharedClient] reachabilityObserver] isReachabilityDetermined] && [[RKClient sharedClient] isNetworkReachable]) {    ....}

You can also subscribe to RKReachabilityObserver notifications (if you want to take any action when reachability status changes)

    [[NSNotificationCenter defaultCenter] addObserver:self                                              selector:@selector(reachabilityStatusChanged:)                                                  name:RKReachabilityDidChangeNotification object:nil];


Here is some changes in RestKit 0.20 and later.The code of reachability block should looks like:

    RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[RemoteTools serverUrl]];[manager.HTTPClient setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {    if (status == AFNetworkReachabilityStatusNotReachable) {        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection"                                                        message:@"You must be connected to the internet to use this app."                                                       delegate:nil                                              cancelButtonTitle:@"OK"                                              otherButtonTitles:nil];        [alert show];    }}];