0

我正在使用导出的API网关IOS SDK。 API最初通过Swagger作为模板导入到API网关,但后来通过AWS门户进行了修改,以映射回IOS SDK中的响应模型和类。所有200个请求返回没有问题。我正在使用pod'AWSAPIGateway','= 2.4.1'AWS API网关导出IOS SDK无错误响应

我遇到的问题是其他问题,然后由IOS SDK处理和/或接收200响应。我知道它是由于Cloudwatch显示正确的映射而发送的,但IOS应用程序中没有返回任何内容。

起初我想也许我是与API网关自己的响应代码冲突,所以我切换到403不在列表中。但那并不奏效。我也没有收到500响应错误。

下面是调用函数:

client.apiRequestPut(apiRequestVar).continueWithSuccessBlock { 
     (task: AWSTask!) -> AnyObject! in 

     print(task) 

     if ((task.error) != nil) { 
      print(task.error) 

      return nil; 
     } 
     if((task.result != nil)) { 

      print(task.result) 

      } 

     } 

     return nil 
    } 

而且AWS SDK生成的客户端功能:

- (AWSTask *)apiRequestPut:(APINewRequest *)body { 
      NSDictionary *headerParameters = @{ 
             @"Content-Type": @"application/json", 
            @"Accept": @"application/json", 

            }; 
NSDictionary *queryParameters = @{ 

            }; 
NSDictionary *pathParameters = @{ 

           }; 

return [self invokeHTTPRequest:@"PUT" 
        URLString:@"/requestVariable" 
       pathParameters:pathParameters 
       queryParameters:queryParameters 
       headerParameters:headerParameters 
          body:body 
       responseClass:[APIModel class]]; 
} 

}

以下是错误示范:

@implementation APIErrorModel 

+ (NSDictionary *)JSONKeyPathsByPropertyKey { 
    return @{ 
      @"success": @"success", 
      @"theFunction": @"theFunction", 
      @"action": @"action", 
      @"timeStamp": @"timeStamp", 
      @"error": @"error", 
      @"data": @"data" 
      }; 
    } 

+ (NSValueTransformer *)timeStampJSONTransformer { 
    return [AWSMTLValueTransformer  reversibleTransformerWithForwardBlock:^id(NSString *dateString) { 
     return [NSDate aws_dateFromString:dateString format:AWSDateISO8601DateFormat1]; 
    } reverseBlock:^id(NSDate *date) { 
     return [date aws_stringValue:AWSDateISO8601DateFormat1]; 
    }]; 

}

这里是API网关400响应代码映射:

#set($inputRoot = $input.path('$')) 
{ 
    "success" : $input.json('$.success'), 
    "theFunction" : "foo", 
    "action" : "foo", 
    "timeStamp" : "foo", 
    "error" : "foo", 
    "data" : $input.json('$.message') 
} 

这里是导致CloudWatch的日志条目:

Endpoint response body before transformations: 
{ 
    "success": false, 
     "message": "{\"message\":\"The conditional request  failed\",\"code\":\"ConditionalCheckFailedException\",\"time\":\"2016-05- 12T20:16:03.165Z\",\"statusCode\":400,\"retryable\":false,\"retryDelay\":0}  " 
} 
    Endpoint response headers: {content-length=217, Connection=keep-alive,  content-type=application/json; charset=utf-8, cache-control=no-cache, Date=Thu, 12 May 2016 20:16:03 GMT 
} 

    Method response body after transformations: 
    { 
    "success": false, 
    "theFunction": "foo", 
    "action": "foo", 
    "timeStamp": "foo", 
    "error": "foo", 
    "data": "{\"message\":\"The conditional request  failed\",\"code\":\"ConditionalCheckFailedException\",\"time\":\"2016-05- 12T20:16:03.165Z\",\"statusCode\":400,\"retryable\":false,\"retryDelay\":0} " 
} 

Method response headers: {Content-Type=application/json} 
Successfully completed execution 
Method completed with status: 400 

但后来我得到的iOS应用收到任何回报?

任何帮助,我失踪将非常感谢!

+0

你想考虑导出到Swagger规范,然后使用[swagger-codegen](https://github.com/swagger-api/swagger-codegen)来生成ObjC SDK(它带有自动生成的doc) –

回答

1

- continueWithSuccessBlock:用于从任务对象中只提取result- continueWithSuccessBlock:中的task对象始终具有nilerror属性。如果您想要收到错误,则需要使用- continueWithBlock:

有关更多详细信息,请参阅Bolts文档。

+0

就是这样!如果它是一条蛇,它会咬我 – jneptune