Comment on page
Leaderboard
Handles Leaderboard requests via IMS web services.
*Identity: In order to opt in to leaderboard, the application must have a valid user (represented by the Identity). That user must be active.
To opt in or join a user into the leaderboard, one can use following snippet.
Swift
Kotlin
let service = LeaderboardService(identity: identity)
service.optIn(then: { result in
switch result {
case .success:
// leaderboard opt in successful
break
case .failure:
// error
}
})
val service = LeaderboardService(identity)
service.optIn() { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})
*Identity: In order to opt out of leaderboard, the application must have a valid user (represented by the Identity). That user must be active.
To opt out or leave the leaderboard, one can use following snippet.
Swift
Kotlin
let service = LeaderboardService(identity: identity)
service.optOut(then: { result in
switch result {
case .success:
// opts out successful
break
case .failure:
// error
}
})
val service = LeaderboardService(identity)
service.optOut() { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})
*Identity: In order fetch leaderboard, the application must have a valid user (represented by the Identity). That user must be active.
To fetch the leaderboard, one can use following snippet.
dateComponents
: The date (by component) to fetch theLeaderboard
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.
Swift
Kotlin
let service = LeaderboardService(identity: identity)
service.fetch(dateComponents: DateComponents(year, month)) { result in
switch result {
case .success:
// fetch succesful
break
default:
// error
}
})
val service = LeaderboardService(identity)
val dataComponents = DataComponents(Date())
val filters = Set<Filter>
service.fetch(dataComponents, filters) { result: Result<Content?>? ->
if (result?.value == null || result.throwable != null) {
// failure
} else {
// Success
val content = result.value
completionHandler(content)
}
})
Last modified 2mo ago