26

If you have a full screen iOS app and you want to prevent the notification center from being pulled down, can you and how?

Also can you block notification alerts or banners from displaying while your app is loading? (I think this is a no way for sure but wanted to ask just in case.)

Rodney S. Foley
  • 10,190
  • 12
  • 48
  • 66

4 Answers4

20

It has been my experience that fullscreen apps (statusBarHidden = YES) have a slightly different notification center behavior by default: Swiping down over the area previously occupied by the status bar will only show a little tab. Only swiping the tab will then show the notification center. This has been enough to prevent accidental activation for me so far.

Currently, there is no public API for manipulating the behavior of the notification center. I am of the opinion that it's not likely that an app will ever be able to block a notification's appearance, and only slightly less unlikely that an app would be able to prevent the notification center from appearing. iOS is all about a consistent user experience experience at the price of developer freedom. I could see being frustrated by this kind of functionality if I were an unexpecting user.

All that said, there is always the dark-side of undocumented APIs. I would not be surprised if you could pull off some cleverness using those on a jailbroken device, but that's not my cup-o'-tea.

Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • Right that tab is what I want to prevent, it interferes with my app and can will many other full screen apps if you finger touches the area where the status bar would be. I couldn't find any obvious public API for this. I plan to make a request on apples bug reporter as I think be able to block the center has justification that Apple may accept, however I don't think blocking notifications will ever happen. And jailbraking isn't an option for me since this already in the app store and I want to continue to have a good relationship with Apple. :) – Rodney S. Foley Oct 14 '11 at 16:57
  • @Rodney: Yeah, I agree with your jailbreaking assessment. It's not something I would ever consider a Solution, but different people have different needs... – Matt Wilding Oct 14 '11 at 17:03
  • 9
    This is a big issue for games. It's very annoying to have this notification come down when your game requires players to be swiping all over the screen. – Roger Gilbrat Feb 19 '12 at 01:12
  • As stated in http://stackoverflow.com/questions/18918427/how-do-you-prevent-notification-center-in-games Angry Birds seems to have a solution... – Kheldar Oct 21 '13 at 11:50
  • @Kheldar That's not a solution. It's the same behavior that's described here: small triangles in square tabs. – bindsniper001 Jun 20 '15 at 19:40
6

I just now figured this out. I am developing a game that runs in landscape and whenever I touched the left side, the notification center tab would appear. To fix this, you want to add the following:

setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft

I added this right after I setStatusBarHidden and I no longer have the problem of the notification tab.

Hope that helps.

Ben Johnson
  • 69
  • 1
  • 1
  • 2
    This does not remove the notification center tab it just moves it to another side. There is currently know way to remove it or prevent it from showing. – Rodney S. Foley Feb 29 '12 at 00:18
3

An API was introduced in iOS 11, alongside a change in behavior to how Notification Center (and Control Center) is presented, to allow you to specify the desired behavior.

UIViewController.preferredScreenEdgesDeferringSystemGestures

In iOS 11+, Notification Center will always pull down when swiping from the very top of the screen, even if the status bar is hidden. preferredScreenEdgesDeferringSystemGestures allows you to specify that swiping a screen edge should not trigger the standard system UI, and instead it will provide a pull-out tab that the user must swipe again to bring out the system UI.

This is intended to be used for games where users swipe frequently, where it would be undesired to bring in system UI instead of control the game. For an immersive app like that, you can return .all to specify you don't want any system UI to appear the first time you swipe any edges of the screen, and it should instead prefer your app's own gestures.

Note that this will disable the ability to swipe once from the bottom to close an app on iPhones and iPads that don't have home buttons - the user will have to swipe twice to close the app.

There is still no way to completely disable Notification Center from within your app, nor prevent notifications from appearing while your app is in the foreground.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
-26

I built a very simple code snippet to address this issue programatically. I have a timer set-up in my app delegate that runs every .2 seconds each time it runs it keeps moving the status bar orientation so it doesn't impact the game play. I haven't experienced the annoying notification center in my app since! The only issue is the volume control rotates constantly and might be annoying but it's less annoying than notification center

int tick=0;

-(void)toggleNC
{
     [[UIApplication sharedApplication] setStatusBarHidden:YES]; 
    tick++;
    if (tick==1)
    {
     [[UIApplication sharedApplication]   setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    }
    if (tick==2){
         [[UIApplication sharedApplication]     setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    }
    if (tick==3){
      [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
   }
    if (tick==4){
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
        tick=0;

    }
}
mike
  • 35