How can I disable the "Welcome, Name!" banner notification for Game Center?
As per this question I've found banners to cause slowdown on iOS 5, it turns out the "welcome, you have been signed in" Game Center message does this too, and on occasion it will interupt me several times in a game if I switch in/out of the app while playing as it logs be in/out repeatedly.
Is there a way to disable this notification while leaving Game Center enabled? I tried revoking the banner notification rights from Game Center but the pop up still appears.
That login banner is a provided aspect of the Game Center API in the iOS SDKs, as far as I'm aware there is no way as a developer to disable it from opening when the Game Center login completes. As a user, there is certainly no way to disable it, because it is part of the application's compiled source code.
However, note that it's not the banner that is causing the delays and skips. It is actually the entire login process to Game Center. My only advice is when you open a game that has Game Center logins, open it up to the first functional screen, and just wait the ~5-10 seconds it takes to reveal the Game Center banner. After the banner has displayed and disappeared, proceed normally and you should not be affected any further.
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!
There does seem to be a way to disable Game Centre, but it's not obvious, or wasn't to me.
Sign out of Game Centre.
If you then start a Game Centre game it will pop up asking you to log in to Game Centre again.
Instead of logging in, press the Cancel button in the top left hand corner. Then Exit the game and repeat until you've opened the game and canceled the Game Centre login three times.
A new dialog pops up asking whether you wish to disable Game Centre. Start the game again and there is none of the Game Centre stuff popping up anymore.
So far this seems to have worked for me. The PITA has kept quiet for now.