进行了很多搜索,但找不到我查询的示例。
我已成功将 sudzc 代码集成到我的项目中,但无法找到将参数传递给函数的方法:
// Returns id
/* Call api functionality */
[service call:self action:@selector(callHandler:) sessionId: @"" resourcePath: @"" args: @"???"];
如果与 sudzc 合作,有人可以告诉我一个例子吗?
提前致谢。
进行了很多搜索,但找不到我查询的示例。
我已成功将 sudzc 代码集成到我的项目中,但无法找到将参数传递给函数的方法:
// Returns id
/* Call api functionality */
[service call:self action:@selector(callHandler:) sessionId: @"" resourcePath: @"" args: @"???"];
如果与 sudzc 合作,有人可以告诉我一个例子吗?
提前致谢。
我自己想出来的。Sudzc 自己没有提供关于如何将参数传递给函数的参考。我也在互联网上进行了广泛的研究,但你不会找到任何提示。所以不要在那里浪费时间。
这个问题的答案是自己以 NSString 的形式创建过滤器模块。在一些帖子中,有人提到我们需要传递一个数组。这是 Sudzc 人员尚未实施的东西,老实说,他们无法理解他们希望我们自己实施什么。
从 Magento 的站点,我找到了一个 SOAP 模块,它显示了过滤器参数的结构。
http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.list.html
在链接的底部,给出了soap请求的结构,我在其他任何地方都找不到。这给了我一个想法。所以我编写了以下函数来生成它们:
-(NSMutableString *)prepareFilter:(NSMutableArray *)items
{
// Prepare args string
NSMutableString *s = [NSMutableString string];
[s appendString:[NSString stringWithFormat:@"<filter SOAP-ENC:arrayType=\"ns1:associativeEntity[%d]\" xsi:type=\"ns1:associativeArray\">", items.count]];
// Add normal filter
for (int cnt=0; cnt<items.count; cnt++)
{
[s appendString:@"<item xsi:type=\"ns1:associativeEntity\">"];
[s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Key"]]];
[s appendString:[NSString stringWithFormat:@"<value xsi:type=\"xsd:string\">%@</value>",[[items objectAtIndex:cnt] objectForKey:@"Value"]]];
[s appendString:@"</item>"];
}
// Closing tag
[s appendString:@"</filter>"];
NSLog(@"%@",s);
return s;
}
-(NSMutableString *)prepareComplexFilter:(NSMutableArray *)items
{
// Prepare args string
NSMutableString *s = [NSMutableString string];
[s appendString:[NSString stringWithFormat:@"<complex_filter SOAP-ENC:arrayType=\"ns1:complexFilter[%d]\" xsi:type=\"ns1:complexFilterArray\">", items.count]];
// Add complex filter
for (int cnt=0; cnt<items.count; cnt++)
{
[s appendString:@"<item xsi:type=\"ns1:complexFilter\">"];
[s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Key"]]];
[s appendString:@"<value xsi:type=\"ns1:associativeEntity\">"];
[s appendString:[NSString stringWithFormat:@"<key xsi:type=\"xsd:string\">%@</key>",[[items objectAtIndex:cnt] objectForKey:@"Operator"]]];
[s appendString:[NSString stringWithFormat:@"<value xsi:type=\"xsd:string\">%@</value>",[[items objectAtIndex:cnt] objectForKey:@"Value"]]];
[s appendString:@"</value>"];
[s appendString:@"</item>"];
}
// Closing tag
[s appendString:@"</complex_filter>"];
NSLog(@"%@",s);
return s;
}
以这种形式将所需的参数传递给这些函数:
NSMutableArray *ary_filterNormal = [NSMutableArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"status",@"Key", @"complete",@"Value", nil],
nil];
[service call:self
action:@selector(callHandler:)
sessionId:[USERDEFAULTS objectForKey:@"SESSION"]
resourcePath:@"sales_order.list"
args:[self prepareFilter:ary_filterNormal]];
所以基本上只需准备请求的结构并将其传递给 args: 进行过滤。