在 v0.20.0 之前的 Restkit 版本中,它曾经足够简单来检查服务不可用性并显示适当的响应。
objectManager.client.serviceUnavailableAlertEnabled = YES;
我们如何在最新的 RestKit 中实现相同的目标?
最佳答案
我自己想出来的。
由于 RKClient 不再出现在最新的 RestKit 中,它已被 AFNetworking 的 AFHTTPClient 取代。 AFNetworking 中的可达性包装器使用起来非常简单。
首先将 SystemConfiguration.framework 添加到您的项目中。
然后添加
#import <SystemConfiguration/SystemConfiguration.h>
给你的.pch
文件。
最后在网络可达性发生变化时注册一个回调 block 。
[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];
}
}];
这也适用于在没有互联网连接的情况下启动应用程序。
关于ios6 - 如何在 RestKit v0.20.0 中设置 serviceUnavailableAlertEnabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14170956/