Yes, it's possible to suppress the Game Center Welcome banner programmatically from within your app, at least under iOS 7. My approach is predicated on a few observations:
- The banner is presented as an additional UIWindow within your UIApplication.
- This window always seems to appear at index 1. (presuming your app only uses one window.)
- The banner is 66 pixels high on iPad, 64 on iPhone.
- The banner contains a 42x42 pixel subview for the Game Center icon.
- It's known when the banner is likely to appear. (i.e. within a few seconds of creating a GKLocalPlayer object on launch to test authentication.)
So you can simply poll your application's windows repeatedly over these few seconds, waiting for the extra window to appear. (Key-value observing is probably the "correct" way to do this, but I'm lazy.) When the window shows up, test whether it contains a subview hierarchy as described above, which indicates that it's probably the Game Center banner. If it is, set the alpha of the window to 0. That's it.
Here's some code that accomplishes this in my app. I call this method immediately after attempting to authenticate the local player, and it calls itself for a few seconds until it finds (and hides) the banner, or else times 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];
}
Once in a while you'll see a single-pixel line flicker at the top of the screen before the banner is hidden, but in general this method seems to work well enough. Use at your own risk, and enjoy!