我正在将iOS应用程序从
Xcode4迁移到
Xcode7(beta 4).通过Pod自动解决对AFNetworking的依赖性. AFNetworking 2.0与AFNetworking 1.0不向后兼容,因此我修改了部分源代码.
Here是
问题如下
/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];
在上面例子的第280行
用NSString替换NSData会导致以下错误
下面的原始AFNetwork-1.0代码
我尝试通过用// 1替换例程来迁移到AFNetwork-2.0
或// 2
没有任何成功
解决方法
我认为NSData编译器错误是一个红色的鲱鱼.问题是,您只为“failure”参数提供了代码块,而不是“constructBodyWithBlock”参数.
尝试类似的东西:
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 } ];
对任何格式问题道歉 – 有降价麻烦.