我想用最新的 AFNetworking 版本 2 更新我的应用程序。从现在起他们改变了一些东西,我想知道如何下载 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 处理 Plist 的任何示例?
我找到了这种方法。这个对吗?
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];