FAQ Database Discussion Community


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

objective-c,afnetworking-2
I have a use case for AFNetworking to behave synchronously (details below). How can I achieve this? Here is my code snippet, which I've simplified as much as possible. I would like to return the success response, but I only ever get nil (because the function returns before the block...

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

php,ios,json,echo,afnetworking-2
I have following HTTP request with AFNetworking: NSMutableDictionary *dictionary = [NSMutableDictionary new]; [dictionary setObject:@"login" forKey:@"request"]; [dictionary setObject:@"q" forKey:@"userName"]; [dictionary setObject:@"q" forKey:@"password"]; DDLogDebug(@"LoginView - login - Dictionary: %@", [dictionary description]); AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager setRequestSerializer:[AFJSONRequestSerializer serializer]]; [manager...

AFNetworking 2: What's it actually sending?

afnetworking-2
I'm using POST:parameters:constructingBodyWithBlock:. I believe the pieces I'm attempting to send to be correct, but I'm getting a HTTP 400 from the server. So something is wrong with the overall packet or how a piece of it is being encoded. I have a few theories about that, but before I...

AFNetworking sending URL as post parameter

ios,objective-c,afnetworking-2,nsurlrequest
I am calling an API in which I am sending a URL link as a post parameter with it. But while converting it into JSON data using NSData* jsonData = [NSJSONSerialization dataWithJSONObject:lParameters options:NSJSONWritingPrettyPrinted error:&error]; it adds extra '\' character into the link. and when I log that data string, it...

Saving image from url to disk not working

objective-c,uiimage,afnetworking,afnetworking-2
I'm trying to download an image from an url in my app, so that it can be used by the Today Extension. So I call [self downloadImageFromUrl:imageOne];, which uses this method: - (void)downloadImageFromUrl:(NSString *)url { NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; requestOperation.responseSerializer = [AFImageResponseSerializer...

AFNetworking 2.0 post not working well

json,flask,afnetworking-2
I use AFNetworking to post some son data to the server, and the server will response with the same json data. Here is the objc code: AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [manager...

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

ios,afnetworking,afnetworking-2,afhttprequestoperation,nsurlerrordomain
This is probably something simple that I am just overlooking. I am trying to make an AFHTTPRequest from uStream's API using AFNetworking. I should be getting a JSON payload response back that lists all the videos on a uStream Channel. Here is my code: NSURL *url = [NSURL URLWithString:@"https://api.ustream.tv/channels/12321320/videos.json"]; NSURLRequest...

remote data fetching inside model object in objective c using AFNetworking

ios,objective-c,rest,model-view-controller,afnetworking-2
In all of my iOS application I use this approach to respect MCV, I want to be sure that my implementation is correct and respects the best practices and the MVC design pattern : Singleton of AFNetworking acting as API for network calls: MyAPI.h : #import "AFHTTPSessionManager.h" #import "AFNetworking.h" @interface...

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

ios,json,rest,ruby-on-rails-4,afnetworking-2
I created one simple Rails app: $ rails new server --database=postgresql $ rails generate scaffold contact name address city zip phone $ git init $ git add . $ git commit -m "initial" $ rake db:create $ rake db:migrate Then I created an iOS client using AFNetworking framework. And I...

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

ios,objective-c,swift,afnetworking-2
I'm trying to do a PATCH request to a server but I always get 404 in my petition, however in the browser I get 200. As far as I can see the PATCH request with AFNetworking is not attaching my parameters to the URL and that's causing the error. Any...

Unable to save AFNetworking responseObject [duplicate]

ios,objective-c,afnetworking-2
This question already has an answer here: Return value from inside block (Objective-C) 1 answer one property: @property (strong, nonatomic)NSDictionary *responseDict; The method: - (void)sendRequestDictionay:(NSDictionary *)dict ToServerWithMode:(NSInteger)mode { NSString *requestString = [self requestStringwithMode:mode]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.requestSerializer = [AFJSONRequestSerializer serializer];...

Trying to port code to AFNetworking 2.0

ios,xcode,afnetworking,afnetworking-2
I am trying to port the following code to AFNetworking 2.0 //load the image API* api = [API sharedInstance]; int IdPhoto = [[data objectForKey:@"IdPhoto"] intValue]; NSURL* imageURL = [api urlForImageWithId:[NSNumber numberWithInt: IdPhoto] isThumb:YES]; AFImageRequestOperation* imageOperation = [AFImageRequestOperation imageRequestOperationWithRequest: [NSURLRequest requestWithURL:imageURL] success:^(UIImage *image) { //create an image view, add it to...

UIImageView+Afnetworking doesn't Work Properly

ios,xcode,uitableview,afnetworking-2
I Have copied the contents of file from here and created a UIImageView+AFNetworking.h and imported in my implementation file Now When I Write the following code i get this error but when i remove the block of code then everything works fine. I want to display image in a custom...

No progression with downloadTaskWithRequest for every url

ios,afnetworking-2
I'm using downloadTaskWithRequest to download some files and I'm using KVO to observe progression. Here is my code : // create the request from an url NSMutableURLRequest *request = [mySession.requestSerializer requestWithMethod:@"GET" URLString:url parameters:nil error:&serializationError]; NSProgress *localProgress = nil; NSURLSessionDownloadTask *downloadTask = [mySession downloadTaskWithRequest:request progress:localProgress destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {...

Use of __IPHONE_OS_VERSION_MIN_REQUIRED without comparison

ios,afnetworking-2
In AFNetworking 2.0, NSHTTPSessionManager.h has the following code: #if __IPHONE_OS_VERSION_MIN_REQUIRED #import <MobileCoreServices/MobileCoreServices.h> #else #import <CoreServices/CoreServices.h> #endif __IPHONE_OS_VERSION_MIN_REQUIRED is used without specifying a version to compare to. Why? Is it because this macro is defined when Core Services framework is changed to MobileCoreServices.h?...

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

ios,objective-c,afnetworking-2
I'm trying to convert some NSURLConnection code to AFNetworking 2.0 and I'm having issues with the POST calls. The GET calls work but not the POST. Here's my code: +(void)login:(User*)myUser { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:myUser.username password:myUser.password]; [manager.requestSerializer setValue:@"application/x-www-form-urlencoded"...

How to convert NSURLConnection to AFNetworking?

ios,objective-c,xcode,afnetworking,afnetworking-2
i want to convert this code to AFNetworking but i have a error. i used AFNetworking POST to REST webservice this code. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSString *latest_url = @"url_string"; [request setURL:[NSURL URLWithString:latest_url]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setValue:useragent_string forHTTPHeaderField:@"User-Agent"]; [request...

imageWithRenderingMode doesn't work with setImageWithUrl (for tintColor)

ios,afnetworking-2
I can tint a UIImage in a UIImageView using : imageView = [[UIImageView alloc]initWithImage:[myImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]]; imageView.tintColor = [UIColor redColor]; But when the image is initialized with AFNetworking's setImageWithUrl : imageView = [imageView setImageWithUrl:url]; imageView.image = [imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageView.tintColor = [UIColor redColor]; This has no effect, the image is displayed with...

using a strong NSProgress with downloadtaskwithrequest

ios,automatic-ref-counting,afnetworking-2
I'm facing a strong vs. autorelease problem : I'm using an object which have a strong NSProgress to manage some file download. For downloading, i'm using downloadtaskwithrequest from AFNetworking. My problem is that this method take a NSProgress * __autoreleasing * which is not compatible with my strong NSProgress :...

AFNetworkActivityManager for AlamoFire?

afnetworking-2,alamofire
AFNetworking allows one to do: [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; But I have not figured out how to do this with the Swift AlamoFire equivalent. I've searched the source for some of the same terms, but don't see anything yet. (I'm learning Swift, so be gentle)....

AFNetworking code giving me Memory Leaks

ios,iphone,memory-leaks,xcode6,afnetworking-2
@implementation GetData static NSString *string = @"https://afternoon-springs-7986.herokuapp.com/"; static NSString *baseStr = @"https://afternoon-springs-7986.herokuapp.com/updateInformation"; -(void) postEventInfo: (NSDictionary *) eventInfoObject { NSURL *url = [NSURL URLWithString:string]; // 6.5% // NSURL *baseURL = [NSURL URLWithString:@"http://localhost:5000/"]; UIWindow *window = [[UIApplication sharedApplication] keyWindow]; UIView *topView = window.rootViewController.view; self.manager = [[AFHTTPSessionManager alloc]...

How to send HTTP POST request with AFNetworking?

ios,objective-c,afnetworking-2
I have a remote address here: http://damp-sands-2243.herokuapp.com/students I need to insert new students via API call. Here is how I did it with javasript: var data = {"name":"Meg", "regi_number":38}; $(document).ready(function(){ $.ajax({ type: "POST", url: "/students/", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify(data), success: function(){console.log("boo");} }); }); You can go to...

NSURL with string relative to URL returning unexpected result

ios,xcode,afnetworking-2,nsurl
This is the call I am making: NSURL *url = [NSURL URLWithString:@"rooms" relativeToURL:[NSURL URLWithString:@"localhost:9000"]]; and the result of url.absoluteURL is: localhost:///rooms does this make sense? I was expecting the result to be localhost:9000/rooms Thanks!...

Image not uploaded on server in iOS

php,ios,objective-c,image-uploading,afnetworking-2
i want to upload an image on to server my image view image for that i write a code like as UIImage *image = self.uploadImageView.image; NSData *imageData = UIImageJPEGRepresentation(image, 0.5); AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:@"http://199.16.128.49/~gzfknsfg/webservices/insert_image.php?foldername=comm_image&img_name=iosimage.jpeg" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFormData:imageData...

AFNetworking GET Parameters in body

ios,web-services,afnetworking-2
I have the following code and I want to force the parameters to be in the body of the GET call and not part of the query string NSString * requestURL = [NSString stringWithFormat:kXXXBaseAPIURL,@"findfriends"]; NSString * lastCallTime = [[XXXCommon sharedInstance] lastTimestampForURL:requestURL]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; AFHTTPRequestSerializer * serializer =[AFJSONRequestSerializer...

AFNetworking User Login asynchron issue

ios,swift,asynchronous,afnetworking-2
When the user presses the button Login, the login-post request will be send. Then I want to fetch the result from this post request, whether it was successful or not. My Post-request: func login (username: String, password: String) -> Bool { var param = ["username": username, "password": password] POST(APIURL.URL_LOGIN, parameters:...

AFNetworking 2.5.3 Serialization of array to send indexes explicitely

ios,afnetworking-2
I use AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer]; and this sends out the call to the server when having an array in the format: payments[] payments[][email]=0& payments[][category]=& payments[][email]=1& payments[][category]=& I need the indexes for the server like. payments[] payments[0][email]=0& payments[0][category]=& payments[1][email]=1& payments[1][category]=& How can I achieve that? Thanks....

setImageWithURL in AFNetworking 2.0

ios,afnetworking,afnetworking-2
In AFNetworking 1.x, we could use setImageWithURL in a way like this: NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO]; [photoView setImageWithURL: imageURL]; } where IdPhoto is the Id of the Photo I am trying to load into an image view. This code doesn't work in AFNetworking 2.0. I think I have...

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

ios,iphone,swift,afnetworking-2
I want to reduce the size of the app to its minimum level. So what all resources i can load from remote after installation? I know I can download images from remote. But can I download libraries or pods from remote after installation? I know we need those files to...

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

php,ios,objective-c,json,afnetworking-2
I do know how to do this, it's fairly simple. The problem is that it doesn't work. Here's the function I use to POST the data: - (void)updateWebsitesUsingParameters:(NSDictionary *)parameters; { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:@"http://notreal/updateWebsites.php" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); //... } failure:^(AFHTTPRequestOperation *operation,...

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

ios,objective-c,unit-testing,afnetworking,afnetworking-2
I've subclassed AFHTTPSessionManager in order to make a mock out of it to use while testing. However, I keep running into a BAD_ACCESS error in AFURLRequestSerialization's init method - only with the mock. Here's the setup: Testing class: @interface PLBookCommunicatorTests : XCTestCase @end @implementation PLBookCommunicatorTests { MockAFHTTPSessionManager *httpSessionManager; HKCommunicator *communicator;...

Response Headers and URL in AFNetworking

ios,objective-c,cocoa-touch,afnetworking-2,nsurlsession
I am using AFNetworking to upload video and Image to a server. NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:urlString parameters:dictParams constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imgData name:@"photo" fileName:@"photo.jpg" mimeType:@"image/jpeg"]; [formData appendPartWithFileData:[NSData dataWithContentsOfFile:pathVideo] name:@"video" fileName:@"video.mp4" mimeType:@"video/mp4"]; } error:nil];...

Download a file with AFHTTPSessionManager and with authentication

ios,oauth-2.0,afnetworking,afnetworking-2
I'm working on an iOS app using OAuth2 authentication. I'm authenticated, I have no problem requesting my API, but I'm facing a problem when trying to download some files from protected URLS. I'm using downloadTaskWithRequest from AFURLSessionManager (AFNetworking). It returns always an error 401 (not authorized) as if I was...

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

ios,objective-c,cocoapods,afnetworking-2
I have added AFNetworking using cocoapods and I need to modify UIActivityIndicatorView+AFNetworking.m category, and more specific I need to add a custom logging statement used in my project to the end of dealloc method. - (void)dealloc { NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000 [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];...

iOS: doubts about Alamofire vs AFNetworking

ios,swift,afnetworking-2,alamofire
now I'm starting a new app Universal (min versione iOS 7) and I want use Switf (it's my second app with this new language) In this app I need the framework AFNetworking, but I have some doubts about compatibility with the new version Alamofire. I know that there are some...

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

ios,afnetworking-2,nsurlsession,background-task
I've built an app around AFNetworking 2.0's AFHTTPSessionManager and its nice HTTP convenience methods. I now need to ensure that all of this networking functionality can run in the background, and I'm rather concerned. Reading Apple's documentation, I can see that data tasks are not supported for background sessions. After...