AFNetworking 2.0 Plist [英] AFNetworking 2.0 Plist

查看:75
本文介绍了AFNetworking 2.0 Plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用最新的AFNetworking版本2更新我的应用程序.自从现在以来,他们已经改变了一些东西,我想知道如何下载plist文件.

I want to update my App with the latest AFNetworking version 2. Since now they have changed some things I was wondering how to download plist files.

我在文档中找到了以下示例:

I found this example in the documentation:

NSURL *URL = [NSURL URLWithString:@"http://example.com/foo.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
                                     initWithRequest:request];
operation.responseSerializer = [AFJSONSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@", responseObject);
} failure:nil];
[operation start];

但是我需要下载一个plist,就像我对AFNetworking 1所做的那样:

But I need to download a plist what I did with AFNetworking 1 like this:

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/test.plist"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
    AFPropertyListRequestOperation *operation = [AFPropertyListRequestOperation propertyListRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList) {

        NSDictionary *myTempDic = (NSDictionary *)propertyList;
        myArray = [myTempDic objectForKey:@"Whatever"];

    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList) {
//do something with the error
}];
[operation start];

在哪里可以找到有关使用AFNetworking 2.0处理Plist的任何示例?

Where can I find any example about handling Plist with AFNetworking 2.0?

我已经找到了这种方法.这是正确的吗?

I have found this way to it. Is this correct?

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFPropertyListResponseSerializer serializer];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id propertyList) {

    NSDictionary *myTempDic = (NSDictionary *)propertyList;
    myArray = [myTempDic objectForKey:@"Whatever"];

    }failure:nil];

    [operation start];

推荐答案

我刚刚在 http ://www.raywenderlich.com/30445/,并且遇到了从1.0到2.0的相同问题

I was just doing the AFnetworking tutorial on http://www.raywenderlich.com/30445/, and had the same problem going from 1.0 to 2.0

我还很新,但这是我发现可以使用的解决方案:

I am fairly new but this is a solution i found to work:

 NSString *url = @"http://example.com/foo.plist";

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

 manager.responseSerializer = [AFPropertyListResponseSerializer serializer];

 [manager GET:url 
   parameters:nil 
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          myArray = [responseObject objectForKey:@"Whatever"]; //responseObject is a dictionary
          NSLog(@"PLIST: %@", responseObject);
      } 
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }];

这篇关于AFNetworking 2.0 Plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆