AFNetworking 2.0 Question POST | replacing obsolete multipartFormRequestWithMethod: path: parameters

I am porting an iOS application from Xcode4 to Xcode7 (beta 4). Dependence on AFNetworking automatically resolved using Pods. AFNetworking 2.0 is not backward compatible with AFNetworking 1.0, so I modified part of the source. There is

  • File structure
  • Magazine and
  • related source code

Problem below

 /Api/ApiClient.m::: error: unexpected interface name 'NSData': expected expression NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding]; ^ /Api/ApiClient.m::: error: use of undeclared identifier 'callerData' NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding]; 

in line 280 of the example above

enter image description here

Substituting NSData with NSString results in the error below

enter image description here

Original AFNetwork-1.0 code below

enter image description here

I am trying to switch to AFNetwork-2.0, replacing the subroutine with either // 1

enter image description here

or 2

enter image description here

without success

+6
source share
2 answers

I think the NSData compiler error is a red herring. The problem is that you are only given a block of code for the failure argument, not the constructingBodyWithBlock argument.

Try something like:

 NSMutableURLRequest* request = [ [ApiManager sharedManager] POST:@"/v1/exec" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { // Code to form the body of the form is here //NSData* callerData = [[NSData alloc] init]; NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding]; [formData appendPartWithFormData:callerData name:@"caller"]; [formData appendPartWithFileData:fontData name:@"front" fileName:@"front" mimeType:@"application/octet-stream"]; [formData appendPartWithFileData:sideData name:@"side" fileName:@"side" mimeType:@"application/octet-stream"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { // Operation success code goes here } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // Operation failed code goes here } ]; 

sorry for any formatting issues - markdown issue.

+7
source
The problem

was unstable (beta)

OS X El Capitan 10.11 Beta (15A244d) | Xcode Version 7.0 beta 4 (7A165t)

I used. what i really expected ...

the above code works fine on stable Yosemite n Xcode 6.4

+4
source

All Articles