我即将更新Objective C中的post项目,以满足仅支持Ipv6的新Apple要求。我的AFNetworking
图片现在是1.2.1。我怀疑这是问题所在。我想更新到最新版本支持IPv6但是在运行pod安装时我收到此错误
[!]无法满足以下要求:
AFNetworking (~> 3.1.0)
要求Podfile
AFNetworking (= 3.1.0)
Podfile.lock
AFNetworking (~> 1.2.1)
AFRaptureXMLRequestOperation (1.0.2)
这是我的完整pod文件
platform :ios, '7.0'
def shared_pods
pod 'RaptureXML'
pod 'Realm'
end
def ios_pods
pod 'AFRaptureXMLRequestOperation'
pod 'GoogleAnalytics-iOS-SDK', '~> 3.0.9'
pod 'KGModal', '~> 0.0.1'
pod 'MagicalRecord'
pod 'MHNatGeoViewControllerTransition', '~> 1.0'
pod 'SVProgressHUD', '~> 1.0'
pod 'UALogger', '~> 0.2.3'
pod 'Reachability', '~> 3.1.1'
pod 'RegexKitLite', '~> 4.0'
pod 'SSKeychain', '~> 1.2.1'
pod 'TTTAttributedLabel'
pod 'TPKeyboardAvoiding', '~> 1.1'
pod 'UIAlertView+Blocks', '~> 0.7'
pod 'UIActivityIndicator-for-SDWebImage', '~> 1.0.3'
pod 'SevenSwitch', '~> 1.3.0'
pod 'ZXingObjC', '~> 3.0'
pod 'DeviceUtil', '~> 1.2'
end
有没有办法将AFRaptureXMLRequestOperation
用于AFNetworking 3.0?或任何其他解决方案?任何帮助都非常感激。感谢
答案 0 :(得分:2)
AFRaptureXMLRequestOperation
子类AFHTTPRequestOperation
,但AFNetworking 3.x中不再存在此类。您将无法将AFRaptureXMLRequestOperation
与AFNetworking 3.x一起使用。
如果您只是使用AFNetworking 3.x解析XML
响应,则可以使用AFXMLParserResponseSerializer
。它返回NSXMLParser
。
因此,为delegate
设置responseObject
,然后在其上调用parse
:
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFXMLParserResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/rss+xml"]; // this line is only needed if parsing RSS feed
[manager GET:@"https://developer.apple.com/news/rss/news.rss" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSXMLParser *parser = responseObject;
parser.delegate = self;
self.titles = [NSMutableArray array];
[parser parse];
NSLog(@"%@", self.titles);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@", error);
}];
但是,您必须编写自己的NSXMLParserDelegate
代码。因此,为了从Apple的RSS源的XML中解析标题,我添加了两个属性:
@property (nonatomic, strong) NSMutableArray *titles;
@property (nonatomic, strong) NSMutableString *elementValue;
然后实现了以下NSXMLParserDelegate
方法:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict {
if ([elementName isEqualToString:@"title"]) {
self.elementValue = [NSMutableString string];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[self.elementValue appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"title"]) {
[self.titles addObject:self.elementValue];
self.elementValue = nil;
}
}