Search and Image Builder works ?
tvisentin opened this issue · 2 comments
tvisentin commented
Hi,
I'm trying to use this wrapper but I'm not sure if I'm in right way ...
let wrapper: IGDBWrapper = IGDBWrapper()
wrapper.userKey = SecretConstants.tokenIGDB
let params: APICalypse = APICalypse()
.search(searchQuery: "Halo")
.fields(fields: "*")
.sort(field: "release_dates.date", order: .DESCENDING)
wrapper.search(apiCalypse: params, result: { searchGames in
let games = searchGames.map { $0.game }
return completionHandler(games, nil)
}) { error in
return completionHandler(nil, "IGDB: Error parsing API")
}
I have a crash here in your code:
public func search(apiCalypse: APICalypse, result: @escaping ([Proto_Search]) -> (Void), errorResponse: @escaping (RequestException) -> (Void)) {
apiRequest(endpoint: .SEARCH, apicalypseQuery: apiCalypse.buildQuery(), dataResponse: { bytes -> (Void) in
let objects = try! Proto_SearchResult(serializedData: bytes).searches
result(objects)
}, errorResponse: errorResponse)
}
In the try! : Thread 13: Fatal error: 'try!' expression unexpectedly raised an error: SwiftProtobuf.BinaryDecodingError.malformedProtobuf
So I can't make a proper search
And if I use games
instead a search
I'm getting some results but I can't have any cover for games or screenshots:
if let hasCover = gameUpdate?.hasCover, hasCover, let cover = gameUpdate?.cover {
let imageURL = imageBuilder(imageID: cover.imageID, size: .HD, imageType: .PNG)
print(imageURL) // "https://images.igdb.com/igdb/image/upload/t_720p/.png"
print(cover.imageID) // ""
}
Do you have any ideas ?
Thank you
joekw commented
I'm getting the same crash when using wrapper.search and wrapper.covers. Works fine with wrapper.games.
joekw commented
It seems like the IGDB API doesn't allow you to use .sort on a search. Remove .sort from your APIcalypse and it will work fine.