Nan*_*ali 2 restkit afnetworking ios6
在v0.20.0之前的Restkit版本中,它过去很简单,可以检查服务不可用性并显示适当的响应.
objectManager.client.serviceUnavailableAlertEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
我们怎样才能在最新的RestKit中实现相同的目标?
Nan*_*ali 11
自己搞清楚了.
由于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];
}
}];
Run Code Online (Sandbox Code Playgroud)
当没有互联网连接时启动应用程序时,这也适用.
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |