diff --git a/android/src/main/java/com/openforge/capacitorgameconnect/CapacitorGameConnect.java b/android/src/main/java/com/openforge/capacitorgameconnect/CapacitorGameConnect.java index 392362e..cc6bc6c 100644 --- a/android/src/main/java/com/openforge/capacitorgameconnect/CapacitorGameConnect.java +++ b/android/src/main/java/com/openforge/capacitorgameconnect/CapacitorGameConnect.java @@ -167,9 +167,12 @@ public void getUserTotalScore(PluginCall call) { @Override public void onSuccess(AnnotatedData leaderboardScoreAnnotatedData) { if (leaderboardScore != null) { - long totalScore = leaderboardScore.getResult().get().getRawScore(); + long userTotalScore = 0; + if (leaderboardScore.getResult().get() != null) { + userTotalScore = leaderboardScore.getResult().get().getRawScore(); + } JSObject result = new JSObject(); - result.put("player_score", totalScore); + result.put("player_score", userTotalScore); call.resolve(result); } } diff --git a/ios/Plugin/CapacitorGameConnect.swift b/ios/Plugin/CapacitorGameConnect.swift index 3b620a0..1095633 100644 --- a/ios/Plugin/CapacitorGameConnect.swift +++ b/ios/Plugin/CapacitorGameConnect.swift @@ -137,6 +137,7 @@ import Capacitor let leaderboardID = String(call.getString("leaderboardID") ?? "") // * Property to get the leaderboard ID let leaderboard = GKLeaderboard() // * LeaderBoard functions + var userTotalScore = 0 // * Property to store user total score leaderboard.identifier = leaderboardID // * LeaderBoard we are going to use for leaderboard.playerScope = .global // * Section to use leaderboard.timeScope = .allTime // * Time to search for @@ -149,20 +150,17 @@ import Capacitor } else if let scores = scores { for score in scores { if score.player.gamePlayerID == GKLocalPlayer.local.gamePlayerID { - let result = [ - "player_score": score.value - ] - call.resolve(result) - break + userTotalScore = Int(score.value) } } } } else { - let result = [ - "player_score": 0 - ] - call.resolve(result as PluginCallResultData) + userTotalScore = 0 } + let result = [ + "player_score": userTotalScore + ] + call.resolve(result as PluginCallResultData) } } } diff --git a/ios/Plugin/CapacitorGameConnectPlugin.swift b/ios/Plugin/CapacitorGameConnectPlugin.swift index 599f117..8644581 100644 --- a/ios/Plugin/CapacitorGameConnectPlugin.swift +++ b/ios/Plugin/CapacitorGameConnectPlugin.swift @@ -42,6 +42,5 @@ public class CapacitorGameConnectPlugin: CAPPlugin { @objc func getUserTotalScore(_ call: CAPPluginCall) { implementation.getUserTotalScore(call) - call.resolve() } } diff --git a/package.json b/package.json index 4c931d4..e2b7f32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openforge/capacitor-game-connect", - "version": "5.0.1", + "version": "5.0.2", "description": "Use Game Services and Game Connect", "main": "dist/plugin.cjs.js", "module": "dist/esm/index.js",