コード例 #1
0
 /**
  * Return the id of a leaderboard (category or identifier, depending on iOS version)
  *
  * @param leaderboard
  * @return
  */
 public String getLeaderboardId(GKLeaderboard leaderboard) {
   if (getIosVersion() >= IOS_7) {
     return leaderboard.getIdentifier();
   } else {
     return leaderboard.getCategory();
   }
 }
コード例 #2
0
  /**
   * Load all the Leaderboards for the Game. Warning: If using iOS5 or less the Leaderboard object
   * will only include the Category (identifier)
   */
  public void loadLeaderboards() {
    // If player is not authenticated, do nothing
    if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) {
      listener.leaderboardsLoadFailed();
      return;
    }

    // If iOS version is 6 or more we use the new method
    if (getIosVersion() >= IOS_6) {
      GKLeaderboard.loadLeaderboards(
          new VoidNSArrayNSErrorBlock() {
            @SuppressWarnings({"rawtypes", "unchecked"})
            @Override
            public void invoke(NSArray array, NSError error) {
              if (error != null) {
                listener.leaderboardsLoadFailed();
              } else {
                ArrayList<GKLeaderboard> leaderboards = new ArrayList<GKLeaderboard>();
                for (NSObject leaderboard : (NSArray<NSObject>) array) {
                  leaderboards.add((GKLeaderboard) leaderboard);
                }
                listener.leaderboardsLoadCompleted(leaderboards);
              }
            }
          });
    } else { // If iOS version is 6 or less we use the deprecated method
      GKLeaderboard.loadCategories(
          new VoidNSArrayNSArrayNSErrorBlock() {
            @SuppressWarnings({"rawtypes", "unchecked"})
            @Override
            public void invoke(NSArray array, NSArray array2, NSError error) {
              if (error != null) {
                listener.leaderboardsLoadFailed();
              } else {
                ArrayList<GKLeaderboard> leaderboards = new ArrayList<GKLeaderboard>();
                for (NSObject category : (NSArray<NSObject>) array) {
                  GKLeaderboard leaderboard = new GKLeaderboard();
                  leaderboard.setCategory(((NSString) category).toString());

                  leaderboards.add(leaderboard);
                }
                listener.leaderboardsLoadCompleted(leaderboards);
              }
            }
          });
    }
  }