我尝试使用从AWS生成的API从本地部分(Objective C)返回到React Native时遇到一些问题API网关。使用AWS Api网关生成的iOS(Objective C)SDK与React Native和回调
我已经在aws中建立了一个简单的测试网关,并且还为该资源创建了一个模型,它看起来像这样。如果没有模式,我无法读取从AWS在客观C.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "dummyConfigModel",
"type": "object",
"properties": {
"config": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"value": {
"type": "string"
},
"placeholder": {
"type": "string"
},
"label": {
"type": "string"
},
"meta": {
"type": "object",
"properties": {
"height": {
"type": "integer"
},
"width": {
"type": "integer"
}
}
}
}
}
}
}
}
好的响应,所以用在地方,我再产生从AWS的API,并得到它安装在我的工作空间。我遵循http://facebook.github.io/react-native/docs/native-modules-ios.html的文档来调用我的本地模块(带回调)。
const NFAWSManager = NativeModules.NFAWSManager;
const config = NFAWSManager.call(
'configGet', {
'dummyKey': 'dummyValue'
},
this.callback);
我的调用由字符串AWS法规划,以避免对每一个变化的API建立新的本地方法,但对于现在的呼叫方法只是执行“configGet”。
的本地部分看起来是这样的:
#import "NFAWSManager.h"
#import "NFReactTestAPIClient.h"
@implementation NFAWSManager
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(
call:(NSString *)method
params:(NSDictionary *)params
callback:(RCTResponseSenderBlock)callback
)
{
NSLog(@"Method was: %@", method);
NSLog(@"Params was: %@", params);
NFReactTestAPIClient *client = [NFReactTestAPIClient defaultClient];
[[client configGet:nil] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
callback(@[task.error]);
}
else {
NFDummyConfigModel *output = task.result;
NSLog(@"DEBUG %@", output);
callback(@[[NSNull null], output]);
}
return nil;
}];
}
@end
好,所以当我把这个从我做出反应基本上什么也没得到。我得到“{}”。但是,如果我硬编码像字符串或字典这样的东西,那么React通常会收到它。
我想我需要帮助的是将task.result对象转换为可传递给React的格式。我怀疑它可能是模型?
看起来像通过在API网关的响应部分完全删除模型将结果转换为可传递的结果。但是,通过删除这个,我怀疑API的Java版本会出现问题。 *我会继续挖掘* – fmortens