本文介绍了将AFNetworking从1.2.1版更新到3.1.0版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iam将更新目标C中的后期项目,以满足Apple仅支持Ipv6的新要求。我的 AFNetworking libray现在是1.2.1。我怀疑这是问题所在。我想更新到支持IPv6的最新版本,但是在运行pod install时出现此错误

Iam about to update our post project in Objective C to meet the new Apple requirement for support Ipv6 only. My AFNetworking libray is now 1.2.1. I doubt it is the problem. I want to update to latest version support IPv6 but when running pod install I get this error

[!]无法满足以下要求:

[!] Unable to satisfy the following requirements:


  • AFNetworking(〜> 3.1.0)是Podfile

  • AFNetworking(= 3.1.0) Podfile.lock

  • AFNetworking(〜1.2.1) AFRaptureXMLRequestOperation(1.0.2)

  • AFNetworking (~> 3.1.0) required by Podfile
  • AFNetworking (= 3.1.0) required by Podfile.lock
  • AFNetworking (~> 1.2.1) required by AFRaptureXMLRequestOperation (1.0.2)

这是我完整的pod文件

Here is my complete pod file

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?或其他解决方案?任何帮助都非常感谢。谢谢

Is there any way to use AFRaptureXMLRequestOperation with AFNetworking 3.0? or any other solution? Any help is much appreciate. Thanks

推荐答案

AFRaptureXMLRequestOperation 子类 AFHTTPRequestOperation ,但此类在AFNetworking 3.x中不再存在。您将无法在AFNetworking 3.x中使用 AFRaptureXMLRequestOperation

AFRaptureXMLRequestOperation subclasses AFHTTPRequestOperation, but this class no longer exists in AFNetworking 3.x. You will not be able to use AFRaptureXMLRequestOperation with AFNetworking 3.x.

如果您只是解析<$在AFNetworking 3.x中使用c $ c> XML 响应,您可以使用 AFXMLParserResponseSerializer 。它返回 NSXMLParser

If you're just parsing XML response with AFNetworking 3.x, you can use AFXMLParserResponseSerializer. It returns a NSXMLParser.

因此,为该 responseObject 设置 delegate ,然后在其上调用 parse

So, set the delegate for that responseObject, and then call parse on it:

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 feed的XML中解析标题,我添加了两个属性:

You'll have to write your own NSXMLParserDelegate code, though. So, to parse the titles out of the XML of Apple's RSS feed, I added two properties:

@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;
    }
}

这篇关于将AFNetworking从1.2.1版更新到3.1.0版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 06:24
查看更多