How to hide the Welcome banner from the game center

I searched this information through the Apple website and document, but could not find the answer ... Do you know if there is a way to hide the "Welcome back, playerName" message from Game Center when the player authenticates

Thanks!

+4
source share
5 answers

No no. You cannot change the behavior of iOS services (in which GameCenter is included) without hacking the device and restarting them. And out of curiosity - why do you need this?

0
source

U can exit Game Center if this is an option for you. Most games are reaction-based, and a notification blocking 15% of the screen for 3 seconds will clearly not be rated.

+1
source

Yes, you can suppress Game Center program code from your application, at least under iOS 7. My approach is based on several observations:

  • The banner is presented as an additional UIWindow in your UIApplication.
  • This window always appears at index 1. (assuming your application uses only one window.)
  • The banner has 66 pixels on the iPad, 64 on the iPhone.
  • The banner contains a 42x42 pixel sublayer for the Game Center icon.
  • It is known that the banner is likely to appear. (i.e. within a few seconds after creating the GKLocalPlayer object at startup for authentication).

Thus, you can simply poll your application windows several times in these few seconds, waiting for an additional window to appear. (Observing key values ​​is probably the β€œright” way to do this, but I'm lazy.) When the window appears, check if it contains a hierarchy of subheadings as described above, which indicates that it is probably a Game Center banner . If so, set the alpha of the window to 0. This.

Here is the code that executes this in my application. I call this method immediately after trying to authenticate the local player, and it calls itself for a few seconds until it finds (and hides) the banner, or until the time runs out:

- (void)suppressGCBanner:(id)object { int osVersion = [[[UIDevice currentDevice] systemVersion] intValue]; if (osVersion != 7) return; // only tested against iOS 7 static int iter = 0; // try for 4 seconds, typically takes about one second for banner to appear static int origWindowCount = 0; NSArray* windows = [UIApplication sharedApplication].windows; if (origWindowCount == 0) origWindowCount = (int)[windows count]; BOOL ipad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad; float bannerHeight = ipad ? 66.0f : 64.0f; // GC banner has height 66 on iPad, 64 on iPhone if ([windows count] > origWindowCount) { NSLog(@"suppressGCBanner: found extra window, testing"); UIWindow* window = [windows objectAtIndex:1]; // in my testing, the GC banner is always at index 1 for (UIView* view in [window subviews]) { CGRect frame = view.frame; NSLog(@"subview size: %f, %f", frame.size.width, frame.size.height); if (frame.size.height != bannerHeight) continue; for (UIView* subview in [view subviews]) { CGRect frame = subview.frame; NSLog(@"sub-subview size: %f, %f", frame.size.width, frame.size.height); if (frame.size.width == 42.0f && frame.size.height == 42.0f) { // Game Center icon is 42x42 NSLog(@"found GameCenter banner: hiding. iter = %i", iter); window.alpha = 0.0f; // make the window invisible! return; } } } } if (++iter > 200) { NSLog(@"suppressGCBanner: timeout, bailing"); return; } // ____ otherwise recurse [self performSelector:@selector(suppressGCBanner:) withObject:nil afterDelay:0.02f]; } 

From time to time you will see the flickering of a single-pixel line at the top of the screen before the banner is hidden, but as a rule, this method works quite well. Use at your own risk and enjoy!

+1
source

Here is 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) } 
+1
source

Here is the working version adapted for swift3:

 NameOfYourClass.suppressGCBanner(0, originalWindowCount: UIApplication.shared.windows.count) static func suppressGCBanner(_ iteration: Int, originalWindowCount: Int) { let windows = UIApplication.shared.windows if windows.count > originalWindowCount { let window = windows[1] if window.responds(to: Selector("currentBannerViewController")) || window.responds(to: Selector("bannerSemaphore")) { print("Found banner, killing it \(iteration)") window.isHidden = true return } } if iteration > 200 { print("suppressGCBanner: timeout, bailing") return } runThisAfterDelay(seconds: 0.02, after: { suppressGCBanner(iteration + 1, originalWindowCount: originalWindowCount) }) } static func runThisAfterDelay(seconds: Double, after: @escaping () -> ()) { DispatchQueue.main.asyncAfter(deadline: .now() + seconds) { after() } } 
0
source

All Articles