【问题标题】:How to set serviceUnavailableAlertEnabled in RestKit v0.20.0如何在 RestKit v0.20.0 中设置 serviceUnavailableAlertEnabled
【发布时间】:2013-01-05 10:38:55
【问题描述】:

在 v0.20.0 之前的 Restkit 版本中,它曾经非常简单,可以检查服务不可用性并显示适当的响应。

objectManager.client.serviceUnavailableAlertEnabled = YES;

我们如何在最新的 RestKit 中实现同样的效果?

【问题讨论】:

    标签: ios6 restkit afnetworking


    【解决方案1】:

    我自己想出来的。

    由于 RKClient 在最新的 RestKit 中不再存在,它已被 AFNetworking 的 AFHTTPClient 取代。 AFNetworking 中的可达性包装器使用起来非常简单。

    • 首先将 SystemConfiguration.framework 添加到您的项目中。

    • 然后将#import <SystemConfiguration/SystemConfiguration.h> 添加到您的.pch 文件中。

    当网络可达性改变时,最后注册一个回调块。

    [objectManager.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];
        }
    }];
    

    这也适用于在没有互联网连接的情况下启动应用程序。

    【讨论】:

    • 以防万一有人在使用 RestKit(包括 AFNetworking)实现此答案时偶然发现 "No visible @interface for HTTPCLIENT declares the selector setReachabilityStatusChangeBlock" 之类的错误:还要确保将 #import <SystemConfiguration/SystemConfiguration.h> 放在 #import <RestKit/RestKit.h> 之前,就像 @987654321 中所述@.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    • 2017-06-20
    • 1970-01-01
    相关资源
    最近更新 更多