簡體   English   中英

如何使用soundcloud Sdk iOS搜索曲目

[英]How to search for tracks using the soundcloud Sdk iOS

我已經閱讀了適用於iOS的soundcloud的sdk文檔,但它似乎沒有說到搜索歌曲的任何內容,盡管它談到了從現有的soundcloud用戶列出曲目。 那么有沒有資源或示例? 太感謝了 !

你必須使用這種格式:

https://api.soundcloud.com/me/tracks?q=SEARCHTEXT&format=json

請記住,如果用戶輸入空格,則必須將其替換為%20 ,您可以實現此目的

NSString *search = [originalSearch stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

然后,只需要像這樣請求JSON數據:

[SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/me/tracks?q=%@&format=json", search]] usingParameters:nil withAccount:[SCSoundCloud account] sendingProgressHandler:nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

我的最終代碼如下所示:

 NSString *search = [searchBar.text stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

[SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/me/tracks?q=%@&format=json", search]] usingParameters:nil withAccount:[SCSoundCloud account] sendingProgressHandler:nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    NSError *jsonError;
    NSJSONSerialization *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];

    if (!jsonError && [jsonResponse isKindOfClass:[NSArray class]]) {

        self.searchQuery = (NSArray *)jsonResponse;
        [self.tableView reloadData];

    }

    else {

        NSLog(@"%@", error.localizedDescription);

    }

}];`

我希望這有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM