Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide "Welcome Back" banner from Game Center login?

I've been looking for this information through Apple documents, but could not find the answer. Soon after I launch my Game Center app there is a pop-up that says:

Welcome back, PlayerName

How can I hide the "Welcome back, playerName" message from Game Center when the player authenticates?

like image 757
Grhyll Avatar asked Nov 04 '22 14:11

Grhyll


1 Answers

Heres a shorter version for Swift:

//Call it right after create this object:
let localPlayer = GKLocalPlayer.localPlayer()
suppressGCBanner(0, originalWindowCount: UIApplication.sharedApplication().windows.count)

////////////////////////////////////////////////////////////////////////

static func suppressGCBanner(iteration: Int, originalWindowCount: Int) {
    let windows = UIApplication.sharedApplication().windows

    if windows.count > originalWindowCount {
        let window = windows[1]

        if window.respondsToSelector("currentBannerViewController") || window.respondsToSelector("bannerSemaphore") {
            print("Found banner, killing it \(iteration)")
            window.hidden = true
            return
        }
    }

    if iteration > 200 {
        print("suppressGCBanner: timeout, bailing")
        return
    }

    runThisAfterDelay(seconds: 0.02, after: {
        suppressGCBanner(iteration + 1, originalWindowCount: originalWindowCount)
    })
}

static func runThisAfterDelay(seconds seconds: Double, after: () -> ()) {
    let time = dispatch_time(DISPATCH_TIME_NOW, Int64(seconds * Double(NSEC_PER_SEC)))
    dispatch_after(time, dispatch_get_main_queue(), after)
}
like image 66
Esqarrouth Avatar answered Nov 15 '22 13:11

Esqarrouth