afnetworking

AFNetworking progress

此生再无相见时 提交于 2019-12-22 09:41:43
问题 I am trying to use setDownloadProgressBlock of AFHTTPRequestOperation class. The call back gives me 3 parameters: ( NSInteger bytesRead , NSInteger totalBytesRead , NSInteger totalBytesExpectedToRead ) In order for me to get the progress, I need the totalBytesExpectedToRead value, but it's giving me a -1. I checked the headers of the HTTP response and the content length is there... { "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; Connection = "Keep-Alive";

How do I make my AFNetworking “responseObject” that I receive a NSDictionary I can parse?

不羁的心 提交于 2019-12-22 09:28:24
问题 I have this call with AFNetworking 1.0 that returns a responseObject with the data from the API that I want: [[AFDiffbotClient sharedClient] postPath:@"http://diffbot.com/api/batch" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { However, I have no idea how to process responseObject . If I check [responseObject class] I get NSData . If I NSLog(@"%@", responseObject) I get a bunch of numbers (memory addresses I assume): <5b0a7b22 68656164 65727322

correct way to embed base64 in json payload with afnetworking

筅森魡賤 提交于 2019-12-22 08:44:30
问题 thanks in advance for any help. I am working with a web service that only takes json payloads and this service is setup for submitting photos. So I am trying to figure out the proper way to embed an image in a json payload. This is my approach. //convert image to nsdata NSData *originalPhoto = UIImageJPEGRepresentation(self.photo.image,.9); //convert the data to a base64 string using NSData+Base64 category extension (Matt Gallagher version) NSString *base64photoString = [originalPhoto

AFNetworking: Access to completion handlers when retrying operation

 ̄綄美尐妖づ 提交于 2019-12-22 05:07:18
问题 To give some context: I'm trying to implement a global error handler for authentication errors (using token authentication, not basic), which should try to re-authenticate and then repeat the original failed request (see my previous question: AFNetworking: Handle error globally and repeat request) The current approach is to register an observer for the AFNetworkingOperationDidFinishNotification which does the re-authentication and (if auth succeeded) repeats the original request: - (void

AFNetworking: Access to completion handlers when retrying operation

↘锁芯ラ 提交于 2019-12-22 05:07:03
问题 To give some context: I'm trying to implement a global error handler for authentication errors (using token authentication, not basic), which should try to re-authenticate and then repeat the original failed request (see my previous question: AFNetworking: Handle error globally and repeat request) The current approach is to register an observer for the AFNetworkingOperationDidFinishNotification which does the re-authentication and (if auth succeeded) repeats the original request: - (void

iOS background fetch time limit crash

怎甘沉沦 提交于 2019-12-21 20:54:51
问题 I've set up background fetch, using outline from NSScreencast episode #92. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; ... } - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if ([[MyAppAPIClient manager] reachable] && [[Session manager]

AFNetworking version 2 content-type error

有些话、适合烂在心里 提交于 2019-12-21 17:49:05
问题 I'm attempting to make an iphone app that will interact with a particular JIRA server. I've got the following code to log in: NSURL *url = [[NSURL alloc] initWithString:@"https://mycompany.atlassian.net/rest/auth/latest/session/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; NSString *postString = [NSString stringWithFormat:@"{\"username\":\"%@\",\"password\":\"%@\"}", username, password]; [request setHTTPBody:[postString

Unable to parse JSON from AFNetworking's responseObject

我与影子孤独终老i 提交于 2019-12-21 12:32:40
问题 I have read this question and trying to parse JSON from AFNetworking's responseObject in Swift but the result is always nil . Here is excerpt from my code: let manager = AFHTTPRequestOperationManager() manager.requestSerializer = AFJSONRequestSerializer() manager.responseSerializer = AFJSONResponseSerializer() manager.requestSerializer.setAuthorizationHeaderFieldWithUsername(username, password: password) manager.POST("endpoint-that-respond-token-in-json", parameters: nil, success: {

why is RestKit changing my response content-type?

↘锁芯ラ 提交于 2019-12-21 12:29:33
问题 In short: I try to fetch data form the server with the content-type of the http request header set as @"text/html .. but for some reason RestKit changes that to application/JSON Explanation: If I were to make this request using just AFNetworking.. things work like a charm.. this is what my AFNetworking code looks like: AFHTTPClient *client = [AFHTTPClient alloc] initWithBaseURL: [NSURL URLWithString:kApiBaseUrl]]; singleton.parameterEncoding = AFJSONParameterEncoding; [singleton

iOS 网络编程:AFNetworking

北城以北 提交于 2019-12-21 08:38:58
1 简介 1.1 概念 AFNetworking 网络框架并不是IOS自带的框架 ,而是第三方的开源框架。它是对NSURLConnection和NSURLSession API的封装,但是目前AFNetworking 3.0已经删除了基于 NSURLConnection API的所有支持,所以本文只记录基于NSURLSession API的相关接口。AFNetworking 框架是基于Object-C语言,若需要使用Swift语言版可以了解 Alamofire 框架。 个人感觉学习AFNetworking 框架非常麻烦,它没有提供guide,所以只能按着GitHub和头文件进行学习。 1.2 第一个程序 1.2.1 环境配置 环境配置非常简单,有多种方式,在GitHub提供了几种方法,这里使用最简单的方式:导入源码。 新建IOS项目后,导入在GitHub网站下载的AFNetworking 源码,如图 2所示。 图 2 1.2.2 源码 其使用如下所示,只需引入AFNetworking.h文件即可使用其API。 1 #include " AFNetworking.h " 2 -( void )DownloadTask 3 { 4 NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration