๊ฐํฌ์ฃผ(Rad) | ๊น์ ๋น(Nini) |
---|---|
๐จ ๋์์ธ ๐จ | ๐ ํ ํฌ ๐ |
https://youtu.be/DZWRW-y7d7Y?si=BJJ8Ft5C82tiEMWN
๋ง์ง ํ๋ฐฉ์ด๋ผ๋ ์ฃผ์ ๋ฅผ ๊ฒ์ด๋ฏธํผ์ผ์ด์ ์ ์ ์ฉํ ๋น๊ณ ๋ฅผ ํตํด ์๋น์ค๋ฅผ ์ ๊ณตํ๋ฉฐ, ๊ฒ์์ผํฐ์ ๊ธฐ๋ฅ์ ํตํด ์๋ฒ๋ฅผ ๋์ ํ์ฌ ์ฌ์ฉ์๊ฐ์ ๊ฒฝ์๊ณผ ์ฌ์ฐธ์ฌ๋ฅผ ์ ๋ํ๋ค.
prototype.mp4
-> ์ธ์ฆ๋์ง ์์ ๊ฒฝ์ฐ, ๊ฒ์ ์ผํฐ ๋ก๊ทธ์ธ ํ๋ฉด์ ํ์ํ์ฌ ํ๋ ์ด์ด๊ฐ ๋ก๊ทธ์ธํ ์ ์๋๋ก ํด์ค
import GameKit
// ๋ก์ปฌ ํ๋ ์ด์ด ์ธ์ฆ ๋ฉ์๋
func authenticateLocalPlayer() {
// ์ด๋ฏธ ์ธ์ฆ ์ค์ด๋ฉด ์ค๋ณต ์คํ ๋ฐฉ์ง
guard !authenticating else { return }
authenticating = true
// ์ธ์ฆ ํธ๋ค๋ฌ ์ค์
GKLocalPlayer.local.authenticateHandler = { [weak self] viewController, error in
guard let self = self else { return }
self.authenticating = false
if let error = error {
print("Authentication failed: \\(error.localizedDescription)")
self.isAuthenticated = false
} else if let viewController = viewController {
// ๋ก๊ทธ์ธ ๋ทฐ ์ปจํธ๋กค๋ฌ๊ฐ ํ์ํ ๊ฒฝ์ฐ ํ์
print("Game Center login required")
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first {
window.rootViewController?.present(viewController, animated: true, completion: nil)
}
} else if GKLocalPlayer.local.isAuthenticated {
// ์ธ์ฆ ์ฑ๊ณต
self.isAuthenticated = true
print("Player authenticated")
} else {
// ์ธ์ฆ ์คํจ
self.isAuthenticated = false
print("Player not authenticated")
}
}
}
// (์์ํ๋ฅผ ์ํ) ๊ฒ์์ผํฐ ์ ์ ์ ์ฅ ๋ฉ์๋
func reportBingoCount(_ count: Int) {
// ์ธ์ฆ ์ฌ๋ถ ํ์ธ
guard isAuthenticated else {
print("Player is not authenticated")
return
}
let score = GKLeaderboardScore()
score.leaderboardID = "์์ํ ID"
// ์์ํ์ ๋ถ์ฌํด์ผ ํ๋ ์์ซ์ ์๋ณ์ - ์ด ID๋ 100์๋ก ์ ํ, ์๊ตฌ์ ์ผ๋ก ์ค์ ๋๋ฉฐ ๋์ค์ ๋ณ๊ฒฝํ ์ ์์
score.value = Int(count)
// ์ ์ ์ ์ฅ
GKLeaderboard.submitScore(score.value, context: 0, player: GKLocalPlayer.local, leaderboardIDs: [score.leaderboardID]) { error in
if let error = error {
print("Failed to report score: \\(error.localizedDescription)")
} else {
print("Score reported successfully")
}
}
}
// ๋ชฉํ(์
์ ) ๋ฌ์ฑ ๋ฉ์๋
func reportAchievement(identifier: String, percentComplete: Double) {
// ์ธ์ฆ ์ฌ๋ถ ํ์ธ
guard isAuthenticated else {
print("Player is not authenticated")
return
}
// ๋ชฉํ ๊ฐ์ฒด ์์ฑ ๋ฐ ์ค์
let achievement = GKAchievement(identifier: identifier)
achievement.percentComplete = percentComplete
achievement.showsCompletionBanner = true
// ๋ชฉํ ๋ฌ์ฑ ๋ณด๊ณ
GKAchievement.report([achievement]) { error in
if let error = error {
print("Failed to report achievement: \\(error.localizedDescription)")
} else {
print("Achievement reported successfully")
}
}
}
// ์์ํ ๋ณด๊ธฐ ๋ฉ์๋
func showLeaderboard() {
let leaderboardID = "์์ํ ID"
let viewController = GKGameCenterViewController(leaderboardID: leaderboardID, playerScope: .friendsOnly, timeScope: .allTime)
viewController.gameCenterDelegate = self
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
if let window = windowScene.windows.first {
window.rootViewController?.present(viewController, animated: true, completion: nil)
}
}
}