功能未正确向eBay API发送请求

时间:2014-03-15 20:39:57

标签: ios objective-c api ebay

我写了一个函数,目的是通过eBay的API将用户输入的内容发送到搜索框中。这是我到目前为止所做的,但它似乎没有正常工作。我很欣赏任何意见。

 - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if (sender != self.nextButton) return;
        if (self.searchField.text.length > 0) {

            NSString *urlAsString = [NSString stringWithFormat:@"http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=***APP ID ***&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=7&keywords=%@", _searchField];
            NSURL *url = [[NSURL alloc] initWithString:urlAsString];
            NSLog(@"%@", urlAsString);
    }

1 个答案:

答案 0 :(得分:0)

将_searchField替换为_searchField.text:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (sender != _nextButton)
    {
        return;
    }

    if (_searchField.text.length > 0)
    {
        NSString *urlString = [NSString stringWithFormat:@"http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=***APP ID ***&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=7&keywords=%@", _searchField.text];
        NSURL *url = [[NSURL alloc] initWithString:urlString];
        NSLog(@"%@", url.absoluteString);
    }
}