Sudzc:如何传递参数或参数来起作用?

时间:2014-07-18 09:03:02

标签: ios parameter-passing sudzc

搜索了很多,但无法找到我的查询示例。

我已成功将sudzc代码集成到我的项目中,但我无法找到将参数传递给函数的方法:

// Returns id
/* Call api functionality */
[service call:self action:@selector(callHandler:) sessionId: @"" resourcePath: @"" args: @"???"];

如果使用sudzc,有人可以给我一个例子。

提前致谢。

1 个答案:

答案 0 :(得分:0)

我自己想通了。关于如何传递函数的参数,Sudzc自己没有给出参考。我也在互联网上进行了广泛的研究,但你不会发现任何暗示。所以不要在那里浪费你的时间。

这个问题的答案是以NSString的形式自己创建过滤器模块。在某些帖子中,有人提到我们需要传递一个数组。 Sudzc人员尚未实施并且诚实的东西无法理解他们希望我们自己实现的目标。

从Magento的网站,我找到了一个SOAP模块,它显示了过滤器参数的结构。

http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.list.html

在链接的底部,有肥皂请求的结构,我在其他任何地方都找不到。这给了我一个主意。所以我编写了以下函数来生成它们:

-(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:进行过滤。