【问题标题】:AFNetworking 2.0 POST issue | replacing deprecated multipartFormRequestWithMethod:path:parametersAFNetworking 2.0 发布问题 |替换已弃用的 multipartFormRequestWithMethod:path:parameters
【发布时间】:2015-07-29 10:23:48
【问题描述】:

我正在将 iOS 应用程序从 Xcode4 迁移到 Xcode7(测试版 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

没有成功

【问题讨论】:

标签: ios objective-c xcode web-services afnetworking-2


【解决方案1】:

我认为 NSData 编译器错误是一个红鲱鱼。问题是您只为“失败”参数而不是“constructingBodyWithBlock”参数提供了一个代码块。

尝试类似:

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
        }
 ];

对任何格式问题表示歉意 - 遇到降价问题。

【讨论】:

  • 我已经尝试过你的建议 - 检查最新的截图,代码注释掉了(//1,//2)
  • 否 - 这两个列表都没有前两个块参数的正文。看看我在上面的答案中有 { } 部分的位置。在您的清单(//1 和 //2)中,您只有一个 { } 代码块用于方法调用的最后一个参数。
【解决方案2】:

问题是不稳定(测试版)

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

我正在使用。我所期待的真的......

上面的代码在稳定的 Yosemite n Xcode 6.4 上运行良好

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2015-08-24
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多