Reputation: 2001
I'm getting a bit frustrated. I'm implementing achievements using GameCenter and Swift 3
However I get the error.
no bundle for bundleID: (null)
I've been following tutorials such as those from raywenderlich.com but can't find any for Swift 3 with achievements (I have leaderboards working) so don't know if my code is incorrect, or how I can just return the bundle IDs programatically to confirm the achievement ID.
To try to get this working in ViewDidLoad I coded the following, and my ViewController is a GKGameCenterControllerDelegate
var achievements = [GKAchievement]()
let fullAchievement = GKAchievement(
identifier: "ReversedIDforMyApp.FullMarks")
achievements.append(fullAchievement)
GameKitHelper.sharedInstance.reportAchievements(achievements: achievements)
I created a helper to report the achievement
func reportAchievements(achievements: [GKAchievement],
errorHandler: ((NSError?)->Void)? = nil) {
guard gameCenterEnabled else {
return
}
GKAchievement.report(achievements,
withCompletionHandler: errorHandler as? (Error?) -> Void)
}
}
I can't work out why the error message would be displayed...
Upvotes: 2
Views: 1050
Reputation: 2001
It would appear that it can take a long time for Apple to set up Game Center achievements, and in the end the code was Ok. Go figure.
Upvotes: 2
Reputation: 322
I might be wrong but try and set the percent and the banner completion on your GKAchievement object.
var achievements = [GKAchievement]()
let fullAchievement = GKAchievement(identifier:"ReversedIDforMyApp.FullMarks")
fullAchievement.percentComplete = 100 //Set this
fullAchievement.showsCompletionBanner = true //Set this
achievements.append(fullAchievement)
GameKitHelper.sharedInstance.reportAchievements(achievements: achievements)
func reportAchievements(achievements: [GKAchievement]) {
guard gameCenterEnabled else {
return
}
GKAchievement.report([achievements]) { (error) in
guard error == nil else {
print("Error in reporting achievements: \(error)")
return
}
}
}
Upvotes: 3