하고자 하는 것
리더보드에 게임점수 제출하기
이를 위해 프로필 만들기 과정인 로그인 부터 진행하였습니다.
환경
- 개발환경 (로컬 호스트)
- 실기기
처음 실행시에, 아래 훅을 실행하였고, 실제로 hash 키가 alert에 노출 되는 것 까지 확인 했습니다.
import { getUserKeyForGame } from "@apps-in-toss/web-framework";
import * as Sentry from "@sentry/nextjs";
import { useEffect, useState } from "react";
export const useLogin = () => {
const [isLoading, setIsLoading] = useState(false);
const [userKey, setUserKey] = useState<string | null>(null);
useEffect(() => {
const fetchUserKey = async () => {
try {
setIsLoading(true);
const result = await getUserKeyForGame();
if (!result) {
// Sentry.captureException(error);
return;
}
if (result === "INVALID_CATEGORY") {
// Sentry.captureException(error);
return;
}
if (result === "ERROR") {
// Sentry.captureException(error);
return;
}
if (result.type === "HASH") {
alert(result.hash); // 테스트 용도로 넣음
setUserKey(result.hash);
}
} catch (error) {
// Sentry.captureException(error);
} finally {
setIsLoading(false);
}
};
fetchUserKey();
}, []);
return { userKey, isLoading };
};
문제 상황
이때, 프로필 만들기 화면이 따로 뜨지 않았습니다.
하지만 hash 값은 잘 생성이 되었어요.
제가 뭔가 실수로 만들었나해서 무시하고 우선.. 이후에 게임 리더보드에 점수 제출을 테스트 해보니, 이것도 제출이 잘 되었습니다. (얼럿 찍어봄)
이후에, 리더보드 열기를 했는데, 점수가 아무것도 나오지 않았습니다.
일부분의 코드도 공유 드립니다.
import { openGameCenterLeaderboard } from "@apps-in-toss/web-framework";
import { isMinVersionSupported } from "@apps-in-toss/web-framework";
import { submitGameCenterLeaderBoardScore } from "@apps-in-toss/web-framework";
import * as Sentry from "@sentry/nextjs";
export function useGameCenterLeaderBoard() {
async function submitScore(score: number) {
try {
const result = await submitGameCenterLeaderBoardScore({
score: score.toString(),
});
if (!result) {
Sentry.captureMessage("지원하지 않는 앱 버전이에요.", {
level: "warning",
tags: {
errorType: "unsupported_app_version",
},
});
return;
}
if (result.statusCode === "SUCCESS") {
alert("점수 제출 성공");
return true;
} else {
Sentry.captureMessage("점수 제출 실패:", {
level: "error",
tags: {
errorType: "score_submission_failed",
},
});
alert("점수 제출 실패");
return false;
}
} catch (error) {
alert("점수 제출 중 오류가 발생했어요.");
Sentry.captureMessage("점수 제출 중 오류가 발생했어요.", {
level: "error",
tags: {
errorType: "score_submission_error",
},
});
}
}
const isSupported = isMinVersionSupported({
android: "5.221.0",
ios: "5.221.0",
});
const openLeaderBoard = async () => {
if (isSupported) {
try {
openGameCenterLeaderboard();
} catch (error) {
Sentry.captureException(error, {
tags: {
errorType: "open_leaderboard_error",
},
});
}
}
};
return { isSupported, submitScore, openLeaderBoard };
}
어떻게 디버깅을 해볼 수 있을까요?