/** * Report an achievement with a percentComplete * * @param identifier * @param percentComplete */ public void reportAchievement(String identifier, double percentComplete) { // If player is not authenticated, do nothing if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) { listener.achievementReportFailed(); return; } GKAchievement achievement = new GKAchievement(identifier); achievement.setPercentComplete(percentComplete); achievement.setShowsCompletionBanner(true); // If iOS version is 6 or more we use the new method if (getIosVersion() >= IOS_6) { // Create an array with the achievement NSArray<NSObject> achievements = new NSArray<NSObject>(achievement); GKAchievement.reportAchievements( achievements, new VoidNSErrorBlock() { @Override public void invoke(NSError error) { if (error != null) { listener.achievementReportFailed(); } else { listener.achievementReportCompleted(); } } }); } else { // If iOS version is 5 or less we use the deprecated method achievement.reportAchievement( new VoidNSErrorBlock() { @Override public void invoke(NSError error) { if (error != null) { listener.achievementReportFailed(); } else { listener.achievementReportCompleted(); } } }); } }
/** * Reset the achievements progress for the local player. All the entries for the local player are * removed from the server. */ public void resetAchievements() { // If player is not authenticated, do nothing if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) { listener.achievementsResetFailed(); return; } GKAchievement.resetAchievements( new VoidNSErrorBlock() { @Override public void invoke(NSError error) { if (error != null) { listener.achievementsResetFailed(); } else { listener.achievementsResetCompleted(); } } }); }
/** Load all the achievements for the local player */ public void loadAchievements() { // If player is not authenticated, do nothing if (!GKLocalPlayer.getLocalPlayer().isAuthenticated()) { listener.achievementsLoadFailed(); return; } GKAchievement.loadAchievements( new VoidNSArrayNSErrorBlock() { @SuppressWarnings({"unchecked", "rawtypes"}) @Override public void invoke(NSArray array, NSError error) { if (error != null) { listener.achievementsLoadFailed(); } else { ArrayList<GKAchievement> achievements = new ArrayList<GKAchievement>(); for (NSObject achievement : (NSArray<NSObject>) array) { achievements.add((GKAchievement) achievement); } listener.achievementsLoadCompleted(achievements); } } }); }