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!
source share