【问题标题】:Using UISearchController to search through an API?使用 UISearchController 搜索 API?
【发布时间】:2023-03-05 07:26:02
【问题描述】:

我目前正在开发一个 iOS 应用程序,该应用程序利用 Spotify API 来检索和播放歌曲。我目前卡在搜索功能上。

我已成功地将 Spotify API (Obj-C) 桥接到我的 Swift 项目中,并且我已经能够创建一个基本搜索,该搜索将搜索/过滤一组硬编码数据。

现在,我想利用在“SPTRequest”类中​​声明的“performSearchWithQuery:queryType:session:callback:”方法,但我不知道该怎么做。我只想搜索歌曲并检索艺术家姓名和歌曲名称。

如果有人能给我一些指导,我将如何去做,我将不胜感激。

谢谢。

https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTRequest.html#//api/name/performSearchWithQuery:queryType:session:callback:

【问题讨论】:

    标签: ios api swift search spotify


    【解决方案1】:

    使用 SPTSearch https://developer.spotify.com/ios-sdk-docs/Documents/Classes/SPTSearch.html

    SPTSearch.perform(withQuery: "Some Query", queryType: .queryTypeTrack, accessToken: session.accessToken) { (error, listPage) 
    
            guard let listPage = listPage as? SPTListPage else { return }
            guard let tracks = listPage.items as? [SPTPartialTrack] else { return } 
    
            for track in tracks {
                   // do something with the track
                   print(track.name)
            }
    }
    

    确保将“-all_load”添加到其他链接器标志,否则 .items 每次都会为零。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多