Menu
  • HOME
  • TAGS

AFNetworking low memory issue

ios,uiimageview,uicollectionview,afnetworking,afnetworking-2

It is not AFNetworking but the image code that is causing the memory usage. JPEG compresses images but when an image is created there will be 4-bytes per pixel. Since the jpeg file on server that is 1.4MB that is all AFNetworking will load. It seems you are using some...

AFNetworking 2 - get error json body [duplicate]

objective-c,json,error-handling,response,afnetworking-2

The answer was simple - operation.responseObject in failure callback contains json data as well. Sweet ^.^

AFNetworking Request failed: unacceptable content-type: text/html

ios,objective-c,afnetworking,afnetworking-2

You are receiving HTML response. To diagnose what's going on, it's useful to see what that HTML actually says. Temporarily change the response serializer to AFHTTPResponseSerializer and then examine the HTML response and it might provide some information that will enlighten you regarding what's wrong with the request. Or you...

AFNetworking User Login asynchron issue

ios,swift,asynchronous,afnetworking-2

It isn't because AFN is using different threads, it's because you aren't dealing with the fact that it is (and you asked it to) properly. That's because your loving method: func login (username: String, password: String) -> Bool { is returning a Bool, but when it returns the asynchronous login...

AFNetworking 2.0: Subclassing AFHTTPSessionManager for TDD causing error in AFURLRequestSerialization init

ios,objective-c,unit-testing,afnetworking,afnetworking-2

This issue was fixed shortly after in release 2.5.1 of AFNetworking: https://github.com/AFNetworking/AFNetworking/releases/tag/2.5.1

Retrieving multiple users from Parse via REST API and using only one AFNetworking request

ios,parse.com,afnetworking,afnetworking-2

You currently have a single dictionary for your query that you convert to JSON NSDictionary *query = @{@"objectId":@"cbfG5dFJy7"}; The or example you show is a dictionary with a single key, where the value is an array of dictionaries like your current query. @{@"$or":@[ @{@"objectId":@""} , @{@"objectId":@""} ]} Once you have...

iOS: doubts about Alamofire vs AFNetworking

ios,swift,afnetworking-2,alamofire

You can just get the Alamofire.swift file in your project, instead of dragging the whole Alamofire project. From Alamofire Github page: Source File For application targets that do not support embedded frameworks, such as iOS 7, Alamofire can be integrated by adding the Alamofire.swift source file directly into your project....

AFNetworking asynchronous POST request for username and password parameter (Objective-C iOS)

php,ios,asynchronous,afnetworking,afnetworking-2

You don't want to use _usernameTextField (the UITextField), but rather _usernameTextField.text or, perhaps better, self.usernameTextField.text (the NSString property of that test field). The same is true with the password. I'd also avail yourself of the POST method: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"userid": self.usernameTextField.text, @"password": self.passwordTextField.text}; [manager...

How to upload task in background using afnetworking

ios,iphone,file-upload,afnetworking-2,nsurlsessionconfiguration

I'm answering my own question in hopes that it will help a few people. I can't find this documented anywhere, but it looks like you have to use uploadTaskWithRequest:fromFile:progress:completionHandler: when using a background session configuration. Here is a simple example: AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate]; id config...

AFNetworking 2.0 post not working well

json,flask,afnetworking-2

You returned JSON data as a response, but your assumption that you set Content-Type is incorrect. Create a response instance with the mimetype set to 'application/json'. from flask import request, json @app.route('/test', methods=['POST']) def test(): data = json.dumps(request.get_json()) resp = app.response_class(data, mimetype='application/json') return resp ...

How to modify a method from category which is added using cocoapods

ios,objective-c,cocoapods,afnetworking-2

You need to stop using it via cocoapods and instead fork your own version of the AFNetworking repo on github and use that instead. In this way you have the opportunity to give any improvements you make back to the community....

AFNetworking sending URL as post parameter

ios,objective-c,afnetworking-2,nsurlrequest

JSON must have certain characters escaped with a "\" character and even though "/" is not required to be escaped it is allowed to be escaped. Therefor the JSON with escaped "/" characters is valid and should be accepted by the API. You can remove them if needed. NSString *jsonString...

Post request Amazon S3 with AFNetworking

objective-c,amazon-web-services,amazon-s3,afnetworking-2

Not really sure why, but changing the below worked for me: postObjectWithFile: to putObjectWithFile: ...

Inheritance, AFNetworking, Good Practices?

ios,inheritance,nsurl,afnetworking-2,nsurlsession

AFNetworking is a very good library for networking. If you need something more advanced than basic stuff and you don't want to reimplement them by yourself, it is a good (best?) choice. Note that AF 2.0 is not compatible with older versions of OSX and iOS, so pay attention to...

How can I POST an NSArray of NSDictionaries inside an NSDictionary without problems?

php,ios,objective-c,json,afnetworking-2

"query string parameterization is simply not a reliable way of encoding nested data structures. This is why all modern web frameworks have built-in conveniences that automatically decode incoming JSON into parameters." - Mattt Thompson So, JSON it is... Parameters: NSDictionary *parameters = @{@"websites" : @[@{@"Title" : @"Google", @"URL" : @"http://www.google.com"},...

AFNetworking is not sending a request

objective-c,afnetworking,afnetworking-2

The request runs asynchronously, and as a result the main function is ending, and thus the app is terminating, before the request is done. You need to have an NSRunLoop running to keep the app alive and process AFNetworking's NSURLConnection events properly. The easiest way to do that is to...

How to solve header issue in AFNetworking?

ios,objective-c,afnetworking-2

You should pass the parameters as NSDictionary, like " NSDictionary *parameters = @{@"UserName": @"[email protected]", @"Password": @"testUserPw", @"grant_type": @"password"}; " This can be achieved using the following code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"UserName": @"[email protected]", @"Password": @"testUserPw", @"grant_type": @"password"}; [manager POST:@"http://apifm.azurewebsites.net/token" parameters:parameters...

AFNetworking change base url

ios,afnetworking-2

If you're switching between base URL's it might just be easier to initialise a new manager each time rather than use a shared one. As much of the benefit of using a shared manager is the single static base URL. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation,...

Serializing JSON into an NSArray with AFNetworking 2.5

ios,objective-c,json,afnetworking,afnetworking-2

Use KVC to obtain array of tracks: NSArray* tracks = [dict valueForKeyPath:@"toptracks.track"] or something like that...

AFNetworking sending NSMutableDictionary as POST

objective-c,afnetworking-2,http-post

If your server is not setting Content-Type header of application/json (or something equivalent), AFHTTPSessionManager will fail. You could theoretically jury-rig the AFNetworking acceptableContentTypes value, but better than that, you should just fix the server code to return the appropriate Content-Type header. But if your server is responding with a 500...

Image Caching With AFNetworking

ios,objective-c,caching,afnetworking-2

NSURLCache does not write to disk in its default so we need to declare a shared NSURLCache in app delegate : NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024 diskCapacity:100 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; Reference...

Unable to save AFNetworking responseObject [duplicate]

ios,objective-c,afnetworking-2

Your question is a similar problem to Returning method object from inside block The block runs asynchronously so it will run after the log statement. You should put the log (indeed you already have a log so you should see it), and the code which uses the result, inside the...

AFNetworking + RNCryptor - decrypt data before JSON parse

objective-c,encryption,yii,afnetworking-2,rncryptor

You say in the response header that the returned data will be JSON ('Content-type: application/json') but it isn't, it's just a bunch of encrypted bytes that were once JSON and can be again after decryption. Either change the header (best) or use a http request that does not see the...

Invalid type in JSON write (NSConcreteMutableData)

json,http-post,afnetworking-2

I have solved the problem by checking my web service in browser. The problem was in my services.php file. There was an error about log file creation and this error was returning a non JSON response that causing the request to fail. My complate working code is here: NSMutableDictionary *dictionary...

AFHTTPSessionManager block is not called when app is on background

ios,background,afnetworking,afnetworking-2,nsurlsessionconfiguration

A couple of thoughts: Proper background NSURLSessionConfiguration requires NSURLSessionDownloadTask or NSURLSessionUploadTask. The GET method, though, creates NSURLSessionDataTask. To use download or upload tasks, you'll have to build your request separately, and then leverage AFURLSessionManager to issue download or upload. Having said that, you can, though, create requests using the various...

AFNetworkActivityManager for AlamoFire?

afnetworking-2,alamofire

Your assessment is correct @travis. There is currently no support for such an activity indicator in the latest version of Alamofire. If you need this functionality, you'll have to build it out on your own at the moment. With that said, I know the project is always accepting PRs having...

AFNetworking code giving me Memory Leaks

ios,iphone,memory-leaks,xcode6,afnetworking-2

Every time you call "postEventInfo", you're creating a AFHTTPSessionManager object. If you're using ARC, this should mean the old object gets released (i.e. not such a problem). But for best practices sake you should do something like this: // set self.manager only if it hasn't been created yet if(!self.manager) {...

UIImage with AFNetworking

ios,uiimage,afnetworking-2

So is this possible ? Yes, it is possible....

AFNetworking 2.0 not parse xml

ios,xml,afnetworking-2

EN: Because the responseObject is a NSXMLParser instance, you can't treat it like string! You have to implement NSXMLParserDelegate to handler the xml parser progress! CN: responseObject返回的是NSXMLParser实例,你必须实现NSXMLParserDelegate协议才能处理该xml字符串!骚年! :-) solution 1: use NSXMLParser to parser [manager GET:@"http://openapi.aibang.com/search?app_key=f41c8afccc586de03a99c86097e98ccb&city=%E5%8C%97%E4%BA%AC&q=%E9%A4%90%E9%A6%86" parameters:nil success:^(AFHTTPRequestOperation...

Is it possible anyhow to load resources to an iOS app after it is installed on device?

ios,iphone,swift,afnetworking-2

For assets (images, movies, sounds, etc...) absolutely. For executable code (libraries, frameworks and pods) absolutely not. That would directly contradict one of the rules that Apple has in place on apps on the App Store. Any executable code has to be bundled and submitted to the App Store for approval....

Can we Integrate AFNetworking in Enterprise level iOS Applications

ios,ios7,ios5,afnetworking,afnetworking-2

AFNetworking is released under the MIT License. Which means you can use it as you like, enterprise or not. Modify and so on. The dev is a great dude. You can read AFNetworking's license here: License File...

Use of __IPHONE_OS_VERSION_MIN_REQUIRED without comparison

ios,afnetworking-2

This is a check if the device is an iOS device or an OS X one. MobileCoreServices is used on iOS while CoreServices is used on OS X. __IPHONE_OS_VERSION_MIN_REQUIRED is only defined on iOS, which is why this works. The other check is MAC_OS_X_VERSION_MIN_REQUIRED, which is only defined on OS...

Having problems using AFNetworking fetching JSON

objective-c,json,afnetworking-2,get-request

You are setting the acceptableContentTypes to text/html. I presume you are doing that because your web-service is not setting the correct Content-Type header to indicate that it's application/json. If you fixed the web service to provide the correct header Content-Type, you could then remove this acceptableContentTypes line in your...

AFNetworking reachability manager for domain - always reachable despite captive portal

ios,afnetworking,afnetworking-2,reachability,captivenetwork

Unfortunately reachability just checks to see if a particular host or dns name responds. Captive portals work, as you have seen from the browser, by responding to all requests in order to display the sign-in page no matter what site the user attempts to access. So reachability says that the...

iOS: JSON pars error when using return instead of echo in PHP service file

php,ios,json,echo,afnetworking-2

In order for AJAX to be able to read output from PHP, PHP has to echo the response. If you use return AJAX is not able to read and use the data as it expects to receive one of several text-like data types: XML, HTML, script, JSON, JSONP, or plain...

Saving image from url to disk not working

objective-c,uiimage,afnetworking,afnetworking-2

You are grabbing the absoluteString (which includes the scheme, amongst other things): NSString *path = [storeUrl absoluteString]; I believe you intended the path: NSString *path = [storeUrl path]; ...

Response Headers and URL in AFNetworking

ios,objective-c,cocoa-touch,afnetworking-2,nsurlsession

You are logging the header with the real response : NSLog(@"%@ %@", response, responseObject); You desired response is just the responseObject apparently a dictionary. NSLog(@"%@", responseObject); For example, you can access the "message" doing : NSLog(@"%@", responseObject[@"message"]); Should log : "Test Button"...

Synchronous calls in an asynchronous environment

ios,objective-c,asynchronous,afnetworking-2,synchronous

You not need to use a synchronous calls. 1) The first way // create request with URL NSMutableURLRequest *request = ....; // create AFHTTPRequestOperation AFHTTPRequestOperation *operation = [[AFHTTPRequestOperationManager manager] HTTPRequestOperationWithRequest:request success:^{success block} failure:^{failure block}]; // Call operation [self.operationQueue addOperation:operation]; In the success block you schedule second operation. 2) The second...

How to send HTTP POST request with AFNetworking?

ios,objective-c,afnetworking-2

This problem was happening because I didn't add the HTTP Header parameter "Accept". So the following line was missing [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; On the other hand I changed the backend in order to preventing it of generating the csrf token while requesting via json by this code skip_before_action :verify_authenticity_token, :if...

Auto synthesis error in AFURLRequestSerialization with Xcode 6

objective-c,afnetworking,afnetworking-2,xcode6

It seems like the version of clang that ships with xcode 6 beta doesn't authorize to rewrite properties in an extension that is not a direct extension of the original class holding those properties. removing: @property (readwrite, nonatomic, assign) NSStreamStatus streamStatus; @property (readwrite, nonatomic, strong) NSError *streamError; and replacing it...

Upload an sqlite file

php,ios,afnetworking-2

The client-side code is uploading using the file field name, but the server code is looking for uploadedfile. You have to use the same field name on both platforms. The mime type should be fixed. Because SQLite files are binary files, not text files, I'd suggest a mime type of...

Problems with SSL Pinning and AFNetworking 2.5.0 (NSURLErrorDomain error -1012.)

ios,ssl,afnetworking,afnetworking-2

After reading through the AFNetworking code & and checking the change logs, here's what I had to do to get this working. Create your AFSecurityPolicy object with AFSSLPinningModeCertificate: AFSecurityPolicy* policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; By default, AFNetworking will validate the domain name of the certificate. Our certificates are generated on a...

AFNetworkActivityLogger's level in SWIFT

swift,afnetworking-2

The AFHTTPRequestLoggerLevel is an enum, so you want: AFNetworkActivityLogger.sharedLogger().level = AFHTTPRequestLoggerLevel.AFLoggerLevelDebug or AFNetworkActivityLogger.sharedLogger().level = .AFLoggerLevelDebug ...

GCDWebServer handlers for background file transfer (Not GCDWebUploader)

ios,afnetworking-2,file-transfer,backgrounding,gcdwebserver

I had this code removed in order to make it work: /* // Add a handler to respond to GET requests [webServer addDefaultHandlerForMethod:@"GET" requestClass:[GCDWebServerRequest class] asyncProcessBlock:^(GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock) { __strong AppDelegate* strongSelf = weakSelf; ..... */ [webServer addHandlerForMethod:@"GET" path:@"/download" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) { __strong AppDelegate* strongSelf =...

AFNetworking issue with UStream API request for channel's video list

ios,afnetworking,afnetworking-2,afhttprequestoperation,nsurlerrordomain

My code was fine but there was an issue with my iphone simulator. Reset Content and Settings did the trick. Thanks to k6sandeep for the help.

Trying to port code to AFNetworking 2.0

ios,xcode,afnetworking,afnetworking-2

responseObject should be your image object, so just use this line: UIImage* image = (UIImage*) responseObject; ...

AFNetworking GET Parameters in body

ios,web-services,afnetworking-2

NSURLConnection which underlies AFHTTPRequestOperation does not allow a body in a GET request. In general GET does not allow a body even though curl does and it usually works on the server. If you want to send a body use a POST request....

How to refresh marker info window in iOS Google maps with AFnetworking Image cache?

ios,google-maps,afnetworking-2

I solved the problem as following I use this property as the info window. @property (nonatomic) MyInfoWindow* infoWindow And this is how I wrote the delegate method of GMSMapViewDelegate - (UIView*)mapView:(GMSMapView*)mapView markerInfoWindow:(GMSMarker*)marker { //Prepare Data MyEvent* selectedEvent = [EventManager eventForEventID:marker.objectID]; //Prepare Thumbnail URL NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[selectedEvent getSmallBannerWithSize:@"w50"]];...

How to convert NSURLConnection to AFNetworking?

ios,objective-c,xcode,afnetworking,afnetworking-2

Since you are using post request, here's what you can do with AFHTTPSessionManager. You can also call AFHTTPSessionManager Get method with block invocation. NSURL *baseURL = [NSURL URLWithString:BaseURLString]; NSDictionary *parameters = @{@"Host": host_string}; AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager POST:@"yourFile.php" parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject)...

why AFNetworking get unsupported url when putting '|' pipe sign in the url

ios,objective-c,google-places-api,afnetworking-2

Are you building this URL yourself? If you used the parameters of a AFNetworking GET request, I believe it would percent escape it properly. But if you build the URL yourself, you're not letting AFNetworking do the necessary percent escaping. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *params = @{@"location" :...

Rails: Error occurred while parsing request parameters. (HTTP PUT)

ios,json,rest,ruby-on-rails-4,afnetworking-2

This doesn't look like json at all: commit=Update%20Contact&contact[address]=xxxxxxx&contact[city]=xxxxxxx&contact[name]=BLA%20BLA%20BLA&contact[phone]=xxxxxxx&contact[zip]=xxxxxxx This looks wrong: manager.requestSerializer = [AFHTTPRequestSerializer serializer]; ... [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; Replace AFHTTPRequestSerializer with AFJSONRequestSerializer...

Change Base URL of AFHTTPSessionManager

ios8,singleton,afnetworking,afnetworking-2

For those interested here is the method I created that I call whenever I need to adjust the Base URL for a call using AFHTTPSessionManager - (AFHTTPSessionManager *) createNewSessionManager { //Load User Defaults NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; //Create url based on user location AFHTTPSessionManager *newDataCall = nil; if (![userDefaults...

Afnetworking 2 basic auth post

ios,http-post,basic-authentication,afnetworking-2

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; NSDictionary *parameters = @{@"Email": username, @"Passwd":password}; [manager POST:@"https://www.inoreader.com/accounts/ClientLogin" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSString *auth = [[string split:@"Auth="] last]; block(auth, nil); }...

Request failed: unacceptable content-type: image/jpg using AFNetworking 2.5

php,ios,json,afnetworking-2

Your PHP script sets a Content-type header in the line just below the comment #Main script You should remove this and respond with the correct mime-type for your image, image/jpeg (include the 'e'). AFNetworking ships with a response serializer, AFImageResponseSerializer, which will automatically decode a response with Content-type image/jpeg into...

AFNetworking different cache settings for different content

ios,caching,afnetworking,afnetworking-2

All cacheable URL requests use the same NSURLCache, whether you're using AFNetworking or not. Creating a new AFNetworking session manager won't make a difference. NSURLCache will move older requests from memory to disk. It's not in the documentation, but I'd bet if stuff is getting purged, then NSURLCache will weigh...

AFNetworking XML Request Issue

ios,afnetworking,afnetworking-2

When you use AFHTTPRequestSerializer your body is created using URL Form Parameter encoding. Your non-AFNetworking example is using XML, so the body looks different. You'll want to do something like this: Instead of using the POST:… convenience method, use the serializer and then set up and enqueue your operation manually:...

remote data fetching inside model object in objective c using AFNetworking

ios,objective-c,rest,model-view-controller,afnetworking-2

I dont have anything to say about your MVC(Model–view–controller) correct? I just want to add something that may be useful approach avoiding unwanted crashes.. First is under [[MyAPI sharedInstance] POST:@"auth/" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) { if([responseObject objectForKey:@"id"]) { [[NSUserDefaults standardUserDefaults] setObject:(NSDictionary*) responseObject forKey:USER_KEY]; [[NSUserDefaults standardUserDefaults] synchronize]; result = [responseObject...

AFNetworking 2: Authorization header not included in request

ios,http-headers,afnetworking-2

I managed to make it work, by using credentials instead of setting the Authorization headers explicitly: NSURL *baseURL = [NSURL URLWithString:WLAPIBaseURL]; AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL]; NSURLCredential *credential = [NSURLCredential credentialWithUser:email password:password persistence:NSURLCredentialPersistenceNone]; manager.credential = credential; [manager GET:WLAPIEndpointMe parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { }...

SSL Certificate validation with AFNetworking

ios,objective-c,nsurlconnection,afnetworking,afnetworking-2

I think you don't understand what HTTP and HTTPS are about: http is the session protocol to communicate with servers without encryption. Everything is sent in the clear and there is also no way to verify the authenticity of the server (i.e. that the server responding is indeed having the...

diacritics signs in url AFNetworking GET

ios,get,diacritics,afnetworking-2

From RFC 3986: When a new URI scheme defines a component that represents textual data consisting of characters from the Universal Character Set [UCS], the data should first be encoded as octets according to the UTF-8 character encoding [STD63]; then only those octets that do not correspond to characters in...

Getting 404 on PATCH Request from AFNetworking (iOS) but 200 from Browser

ios,objective-c,swift,afnetworking-2

instead: httpRequestOperationManager.PATCH(...) try use: httpRequestOperationManager.GET(...) ...

AFNetworking param serialization error

ios,afnetworking-2

The multipart/form-data request is expecting a series of key-value pairs (or files or what have you), but the "value" associated with invitees key appears to be a description of a NSDictionary, which is going to be awkward to parse (as it doesn't conform to any established standards). You could, theoretically,...

Image not uploaded on server in iOS

php,ios,objective-c,image-uploading,afnetworking-2

change the following line [formData appendPartWithFormData:imageData name:@"name"]; to [formData appendPartWithFileData:imageData name:@"img_name" fileName:@"iosimage.jpg" mimeType:@"image/jpeg"]; and it should work. :)...

Download a file with AFHTTPSessionManager and with authentication

ios,oauth-2.0,afnetworking,afnetworking-2

ok, I was creating my request the wrong way : NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; this was the good way : NSMutableURLRequest *request = [mySessionManager.requestSerializer requestWithMethod:@"GET" URLString:url parameters:nil error:&serializationError]; ...

AFNetworking Issue - Cancel Operation when dismissing view controller

ios,objective-c,afnetworking-2

A good practice to avoid this kind of crash is to separate the Data from the View controllers. Basically you would have data manager that will hold the data, this will be a singleton that will live for the entire app session. A view controller would read data from this...

No progression with downloadTaskWithRequest for every url

ios,afnetworking-2

The HTTP Response object that I get from the URL must contains a header called Content-Length which will give the length of the file ! If the server doesn't return this, it seems to be impossible to track download progression....

svprogresshud not showing on main thread

ios,objective-c,afnetworking-2

The problem is you are showing hud immediately after method call like [self getData]; [SVProgressHUD dismiss]; This is the problem. Move dismiss code to -(void) getData { AFHTTPRequestOperationManager * reqManager =AFHTTPRequestOperationManager manager]; AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer]; //set auth token..etc [reqManager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { //code for...

AFNetworkingErrorDomain Code=-1011 “Request failed: internal server error (500)”

ios,afnetworking-2

According to the elements you've added in your edited version, it seems like you're not sending out JSON data in the format that is expected by the server. The server is expecting a dictionary with blog_guid and contact_groups items, the latter itself being an array of strings. You have to...

Semaphore wait causing a block of AFNetworking?

objective-c,multithreading,unit-testing,afnetworking-2

Okay... the primary problem was the queues for AFNetworking AND the Notification were on the main thread. The semaphore is blocking the main thread, so both responses were blocked. For the testing, a new NSOperationQueue had to be specified in place of the mainQueue. For the networking class, a new...

imageWithRenderingMode doesn't work with setImageWithUrl (for tintColor)

ios,afnetworking-2

Your code has no effect because you are assigning the image to be fetched from the remote URL, which takes time and thus happens later - after your code has finished. Thus, this line does nothing: imageView.image = [imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; ...because, at the time it runs, imageView.image is still nil....

setImageWithURL in AFNetworking 2.0

ios,afnetworking,afnetworking-2

To make this code work, you need to import <UIImageView+AFNetworking.h>

AFNetworking 2: What's it actually sending?

afnetworking-2

For anyone curious later, I've found this works nicely in the failure or success block: NSMutableData *data = [NSMutableData data]; NSInputStream *stream = [operation.request.HTTPBodyStream copy]; [stream open]; BOOL done = NO; while (!done) { NSMutableData *buffer = [NSMutableData dataWithLength:1024]; buffer.length = [stream read:buffer.mutableBytes maxLength:buffer.length]; if (buffer.length) { [data appendData:buffer]; }...

Wait for AFNetworking completion block before continuing (i.e. Synchronous)

objective-c,afnetworking-2

It sounds like there's a part of your app that can't run until a starting request is done. But there's also a part that can run (like the part that starts the request). Give that part a UI that tells the user that we're busy getting ready. No blocking the...

How to show ProgressBar With AFNetworking AFHTTPRequestOperationManager

ios,objective-c,afnetworking-2,uiprogressview

You set the download-progress-block inside the success block, which is a bit too late ;) Try this: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; AFHTTPRequestOperation *operation = [manager GET:@"https:urlWithJson" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Complete"); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead,...

using a strong NSProgress with downloadtaskwithrequest

ios,automatic-ref-counting,afnetworking-2

It's downloadTaskWithRequest who initialize the NSProgress object, so I cannot give it directly a NSProgress which is property of my object, i had to create another NSProgress object, and to update my property when needed : -(void)downloadFileFromUrl:(NSString*)url progress:(NSProgress * __strong *)progress { NSProgress *localProgress = nil; NSURLSessionDownloadTask *downloadTask = [self...

AFNetworking alters JSON response?

ios,swift,afnetworking-2

Because it isn't printing JSON, it's printing the object graph that was generated from the JSON (a combination of instances of NSArray, NSDictionary, NSString, ...). i.e. AFNetworking has already done a bunch of work for you to deserialise the data that was received....

AFNetworking 2.5.3 Serialization of array to send indexes explicitely

ios,afnetworking-2

AFHTTPRequestSerializer has a method setQueryStringSerializationWithBlock which allows you to provide your own block for serializing the parameters. Unfortunately, the internal AF* functions for serialization are private, but you can copy them and make a small modification in these lines to add the indexes. To set your own serialization block: [serializer...

multiple files with appendPartWithFileData

ios,iphone,afnetworking-2

I got it : [formData appendPartWithFileData:fileData1 name:@"files[file1[data]]" fileName:fileName1 mimeType:mimeType1]; [formData appendPartWithFileData:fileData2 name:@"files[file2[data]]" fileName:fileName2 mimeType:mimeType2]; ...

Swift Custom Response Serializer is returning images at random

swift,uiimage,afnetworking,afnetworking-2,alamofire

Somehow the images get appended at a random order, why? Because order is not guaranteed for asynchronous requests or blocks dispatched asynchronously. Instead of appending images into an array, you should key them into a dictionary according to their corresponding page (e.g. pages[i] = image) (by the way, it's...

if I call an async operation in one view controller and the user moves to the next view controller, does the async call finish

ios,afnetworking,afnetworking-2,nsoperationqueue,sdwebimage

The GET, POST, etc., methods of AFHTTPSessionManager return NSURLSessionTask references. If you leave the controller that initiated the request, the request will continue unless you (a) save a reference to that NSURLSessionTask object; and (b) explicitly call the cancel method for that object. SDWebImage method downloadWithURL likewise returns a reference...

AFNetworking 2 - Image upload - Request failed: unsupported media type (415)

objective-c,osx,afnetworking-2,nsimage

With the support of Mattijs from TinyPNG I've got it working! Thanks Mattijs! The problem was, that the TinyPNG API expects the request body to only be the image data, which isn't the case with the multipart form data body I used in my original code. My working solution is:...

How to periodically poll/pull from a REST interface using AFNetworking in iOS

ios,objective-c,networking,afnetworking,afnetworking-2

Use Grand Central Dispatch: @property (strong, nonatomic) dispatch_source_t timer; - (void)startTimer { if (!self.timer) { self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue()); } if (self.timer) { dispatch_source_set_timer(self.timer, dispatch_walltime(NULL, 0), 60ull*NSEC_PER_SEC, 10ull*NSEC_PER_SEC); dispatch_source_set_event_handler(_timer, ^(void) { [self tick]; }); dispatch_resume(_timer); } } - (void)tick { // Do your REST query here } This...

AFNetworking 2.0 header Content-Type not being sent on POST call

ios,objective-c,afnetworking-2

Your server is sending you text/html whether you like it or not. So you have to make this an acceptable content type in the request serializer. You can either add it, like this: manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"]; or use a more general HTTP serializer, not a JSON serializer, like this:...

UIImageView+Afnetworking doesn't Work Properly

ios,xcode,uitableview,afnetworking-2

Instead of using afnetworking You can just use dispatch method dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(queue, ^{ NSString *url = [indexDic objectForKey:@"image"]; NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; UIImage *image = [UIImage imageWithData:imageData]; dispatch_async(dispatch_get_main_queue(), ^{ cellImg.image = image; }); }); return cell; } ...

setting a request header for an authorization token in afnetworking

ios,objective-c,json,header,afnetworking-2

You don't need a AFJSONRequestSerializer you need a AFJSONResponseSerializer request => response and AFJSONResponseSerializer is the default responseSerializer so just don't change requestSerializer...

How to view Swift API of AFNetworking?

objective-c,swift,afnetworking,cocoapods,afnetworking-2

You can use Alamofire (swift version of AFNetworking) : https://github.com/Alamofire/Alamofire

Passing tuple to AFNetworkingRequestManger.GET in Swift

ios,swift,tuples,afnetworking,afnetworking-2

It seems that it is not possible to pass a tuple as parameter values to objective-c code.

NSURL with string relative to URL returning unexpected result

ios,xcode,afnetworking-2,nsurl

You are missing a scheme. NSURL seems to interpret the localhost: part as scheme, which causes unexpected behaviour. In case of http you should try this: NSURL *url = [NSURL URLWithString:@"rooms" relativeToURL:[NSURL URLWithString:@"http://localhost:9000/"]]; ...

AFNetworking saves cookies created on server forever?

ios,objective-c,node.js,cookies,afnetworking-2

There used to be a bug when using POST and clearing cookies on AFNetworking. Not sure what version you are using though. My guess is that it's still stored in AFNetworking and sent upon the next requests. Have you tried clearing the cookies on the client-side (in AFNetworking?) Something like:...

NSURLSessionDownloadTask and retrying

ios,objective-c,objective-c-blocks,afnetworking-2

You could create a retryCount instance variable and set it to however many times you want to retry the network call. Then you could put all your networking code in a method with a custom completion handler. Your completion handler could be a block that takes a BOOL as a...

AFHTTPSessionManager convenience methods (GET, POST, PUT, etc) and background transfers

ios,afnetworking-2,nsurlsession,background-task

AFNetworking allows you to perform background requests (though be careful to not use any of the task-specific completion blocks and make sure you implement the appropriate app delegate methods; see AFNetworking 2.0 and background transfers). You probably also can use requestWithMethod of AFHTTPRequestSerializer to simplify the process of building the...