2013-10-28 67 views
0

我想用最新的AFNetworking版本2更新我的应用程序。从现在开始,他们改变了一些我想知道如何下载plist文件的东西。AFNetworking 2.0 Plist

我发现这个例子中的文档中:

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这样的:

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一起上榜?

我已经找到了这个方法。它是否正确?

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

回答

2

我只是做了AFnetworking教程http://www.raywenderlich.com/30445/,不得不去从1.0到2.0

我是相当新的同样的问题,但是这是一个解决方案,我发现工作:

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