如何获取afnetworking download 文件
1个回答
展开全部
首先载AFNetworking库文件载首先弄清楚要发软件兼容低版本少AFNetworking2.0或者版本需要xcode5.0版本并且能IOS6或更高手机系统运行发MAC程序2.0版本能MAC OS X 10.8或者更高版本运行
想要兼容IOS5或MAC OS X 10.7需要用新发布1.x版本
要兼容4.3或者MAC OS X 10.6需要用新发布0.10.x版本
何通URL获取json数据
第种利用AFJSONRequestOperation官网站给例:
NSString *str=[NSString stringWithFormat:@" /stream/0/posts/stream/global"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// URL获取json数据
AFJSONRequestOperation *operation1 = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSDictionary* JSON) {
NSLog(@"获取数据:%@",JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id data) {
NSLog(@"发错误%@",error);
}];
[operation1 start];
第二种利用AFHTTPRequestOperation 先获取字符串形式数据转换json格式NSString格式数据转换json数据利用IOS5自带json解析:
NSString *str=[NSString stringWithFormat:@""];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, idresponseObject) {
NSString *html = operation.responseString;
NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
id dict=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"获取数据:%@",dict);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"发错误%@",error);
}];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
发Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x14defc80 {NSUnderlyingError=0x14deea10 "bad URL", NSLocalizedDescription=bad URL错误请检查URL编码格式没进行stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
何通URL获取图片
异步获取图片通队列实现且图片缓存请求相同链接系统自调用缓存网请求数据
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 100.0f, 100.0f, 100.0f)]; [imageView setImageWithURL:[NSURL URLWithString:@""]placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]]; [self.view addSubview:imageView];
面官提供种
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@""]];
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:nil success:^(NSURLRequest *request, NSHTTPURLResponse*response, UIImage *image) {
self.backgroundImageView.image = image;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Error %@",error);
}];
[operation start];
使用第种URLWithString: placeholderImage:更细节处理其实实现通AFImageRequestOperation处理点击URLWithString: placeholderImage:进看目所我觉用第种
何通URL获取plist文件
通url获取plist文件内容用少官提供面没
NSString *weatherUrl = @" /buick/kls/Buickhousekeeper.plist";
NSURL *url = [NSURL URLWithString:[weatherUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[AFPropertyListRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/plain"]];
AFPropertyListRequestOperation *operation = [AFPropertyListRequestOperation propertyListRequestOperationWithRequest:request success:^(NSURLRequest *request,NSHTTPURLResponse *response, id propertyList) {
NSLog(@"%@",(NSDictionary *)propertyList);
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, idpropertyList) {
NSLog(@"%@",error);
}];
[operation start];
何通URL获取XML数据
xml解析使用AFXMLRequestOperation需要实现苹自带NSXMLParserDelegate委托XML些需要协议格式内容所能像json解析实现委托我前想能否所XML链接用类处理且跟服务端做沟通结便效XML标签同格式固定所问题使用json要便
想要兼容IOS5或MAC OS X 10.7需要用新发布1.x版本
要兼容4.3或者MAC OS X 10.6需要用新发布0.10.x版本
何通URL获取json数据
第种利用AFJSONRequestOperation官网站给例:
NSString *str=[NSString stringWithFormat:@" /stream/0/posts/stream/global"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// URL获取json数据
AFJSONRequestOperation *operation1 = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSDictionary* JSON) {
NSLog(@"获取数据:%@",JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id data) {
NSLog(@"发错误%@",error);
}];
[operation1 start];
第二种利用AFHTTPRequestOperation 先获取字符串形式数据转换json格式NSString格式数据转换json数据利用IOS5自带json解析:
NSString *str=[NSString stringWithFormat:@""];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, idresponseObject) {
NSString *html = operation.responseString;
NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
id dict=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"获取数据:%@",dict);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"发错误%@",error);
}];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
发Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x14defc80 {NSUnderlyingError=0x14deea10 "bad URL", NSLocalizedDescription=bad URL错误请检查URL编码格式没进行stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
何通URL获取图片
异步获取图片通队列实现且图片缓存请求相同链接系统自调用缓存网请求数据
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 100.0f, 100.0f, 100.0f)]; [imageView setImageWithURL:[NSURL URLWithString:@""]placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]]; [self.view addSubview:imageView];
面官提供种
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@""]];
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request imageProcessingBlock:nil success:^(NSURLRequest *request, NSHTTPURLResponse*response, UIImage *image) {
self.backgroundImageView.image = image;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Error %@",error);
}];
[operation start];
使用第种URLWithString: placeholderImage:更细节处理其实实现通AFImageRequestOperation处理点击URLWithString: placeholderImage:进看目所我觉用第种
何通URL获取plist文件
通url获取plist文件内容用少官提供面没
NSString *weatherUrl = @" /buick/kls/Buickhousekeeper.plist";
NSURL *url = [NSURL URLWithString:[weatherUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[AFPropertyListRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/plain"]];
AFPropertyListRequestOperation *operation = [AFPropertyListRequestOperation propertyListRequestOperationWithRequest:request success:^(NSURLRequest *request,NSHTTPURLResponse *response, id propertyList) {
NSLog(@"%@",(NSDictionary *)propertyList);
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, idpropertyList) {
NSLog(@"%@",error);
}];
[operation start];
何通URL获取XML数据
xml解析使用AFXMLRequestOperation需要实现苹自带NSXMLParserDelegate委托XML些需要协议格式内容所能像json解析实现委托我前想能否所XML链接用类处理且跟服务端做沟通结便效XML标签同格式固定所问题使用json要便
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询