Handles Leaderboard requests via IMS web services.
Opt in
Required information
*Identity: In order to opt in to leaderboard, the application must have a valid user (represented by the Identity). That user must be active.
Concrete Example
To opt in or join a user into the leaderboard, one can use following snippet.
let service =LeaderboardService(identity: identity)service.optIn(then: { result inswitch result {case .success:// leaderboard opt in successfulbreakcase .failure:// error }})
val service =LeaderboardService(identity)service.optIn() { result: Result<Content?>? ->if (result?.value==null|| result.throwable !=null) {// failure } else {// Successval content = result.valuecompletionHandler(content) }})
Opt out
Required information
*Identity: In order to opt out of leaderboard, the application must have a valid user (represented by the Identity). That user must be active.
Concrete Example
To opt out or leave the leaderboard, one can use following snippet.
let service =LeaderboardService(identity: identity)service.optOut(then: { result inswitch result {case .success:// opts out successfulbreakcase .failure:// error }})
val service =LeaderboardService(identity)service.optOut() { result: Result<Content?>? ->if (result?.value==null|| result.throwable !=null) {// failure } else {// Successval content = result.valuecompletionHandler(content) }})
Fetch
Required information
*Identity: In order fetch leaderboard, the application must have a valid user (represented by the Identity). That user must be active.
Concrete Example
To fetch the leaderboard, one can use following snippet.
Parameters:
dateComponents: The date (by component) to fetch the Leaderboard for. Leaderboards are fetched by month, so specifying the year and month in the components are necessary to receive the correct leaderboard. Defaults to fetching the current leaderboard.
let service =LeaderboardService(identity: identity)service.fetch(dateComponents: DateComponents(year, month)) { result inswitch result {case .success:// fetch succesfulbreakdefault:// error }})