Get Available Challenges

Get all active available challenges that a logged in user is eligible for. Note: Requires an active Versus Session. Challenges are paginated by default - page and pagesize below will afford the ability to retrieve results in a performant manner.

Android

/**
* @property page Page to request if there are multiple pages of challenges
* @property pageSize The maximum number of challenges that will come back per page.
* @property eligible: Only show challenges for which the currently authenticated user is eligible
* @property filterByPrizeTypeIds [Optional]: Optionally only return challenges that have these prize id's
*
* @return VsLiveData<Array<Challenge>> object. Array of available challenges.
*/
fun getAvailableChallenges(
  page: Int = 1,
  pageSize: Int = 10,
  eligible: Boolean = true,
  filterByPrizeTypeIds: List<String>? = null
): VsLiveData<Array<Challenge>>
val page: Int = 1
val pageSize: Int = 10
val onlyShowEligible = true

SDK.Challenges.getAvailableChallenges(page, pageSize, onlyShowEligible)
  .observe(object : VsObserver<Array<Challenge>>() {
    override fun onError(error: Throwable) {
    }

    override fun onChanged(t: Array<Challenge>) {
    }
})

Get the next set of available challenge results for your game. Note: If you don't want to manually configure pagination, this can handle it for you and just continue to provide the next set of results.

/**
* @return VsLiveData with an array of Versus Challenges on success
*/
fun getNextAvailableChallenges(): VsLiveData<Array<Challenge>>
SDK.Challenges.getNextAvailableChallenges().observe(object : VsObserver<Array<Challenge>>() {
  override fun onError(error: Throwable) {
  }

  override fun onChanged(t: Array<Challenge>) {
  }
})

iOS

/// - Parameters:
///     - onlyShowEligible: This will filter the challenges to only show those the current player is eligible to join.
///     - rankLimit: This will filter the challenges and only show challenges for which the players rank qualifies. (defaults to 0)
///     - pageNumber: Page of results to pull (defaults to 1)
///     - pageSize: Size of each pages results (defaults to 10)
///     - completionHandler: Closure which returns a Versus Session (or Error)
getChallenges(onlyShowEligible: Bool, rankLimit: Int = 0, pageSize: Int, pageNumber: Int,
                                          completionHandler: @escaping VersusApiResponse<ChallengeResponse>)
VersusSDK?.getAvailableChallenges(pageNumber: 1, pageSize: 10, completionHandler: { (challengeResponse, error) in
    if error != nil {
        // error occurred
    } else {
        // Successfully fetched current challenges (contained inside ChallengeResponse object)
    }
})