1

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) required by Podfile
  • AFNetworking (= 3.1.0) required by Podfile.lock
  • AFNetworking (~> 1.2.1) required by AFRaptureXMLRequestOperation (1.0.2)

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

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lê Khánh Vinh
  • 2,591
  • 5
  • 31
  • 77

1 Answers1

2

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.

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

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);
}];

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;

And then implemented the following NSXMLParserDelegate methods:

- (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;
    }
}
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thanks for your explanation. I try again. My problem is to upgrade these manager to work with AFNetworking 3.x. Can you help to look at these file and suggest any change to migrate? many thanks! !https://1drv.ms/f/s!At_ezahqccq3it1dbThVHBz9hok1xw – Lê Khánh Vinh Jul 25 '16 at 18:26
  • You have to replace `AFHTTPClient` with `AFHTTPSessionManager`, and replace your `AFHTTPRequestOperation` with `GET` and `POST` calls (as appropriate). And, as outlined above, you have to replace `AFRaptureXMLRequestOperation` with `GET`/`POST` with `AFXMLParserResponseSerializer`. – Rob Jul 25 '16 at 20:47
  • Thanks. I'm still struggle with these migration. Can help take a look at actual method here?http://stackoverflow.com/questions/38580561/afnetworking-3-x-migration-and-xml-parser – Lê Khánh Vinh Jul 26 '16 at 03:50