Disabling NC, CC and Home gestures

From iPhone Development Wiki
Revision as of 06:38, 22 October 2018 by PoomSmart (talk | contribs) (Revision.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In iOS 9-11, we have the class SBSystemGestureManager which helps a great deal. It has a method _isGestureWithTypeAllowed: which is called early in the gestures and can be used to see which ones are being invoked.

   %hook SBSystemGestureManager
   
   -(BOOL)_isGestureWithTypeAllowed:(NSUInteger)type {
       NSLog(@"_isGestureWithTypeAllowed [%u]", type);
   
       // iOS 11 - Normal device (11.0.3)
       // ===============================================================
       // 1 = Notification center
       // 2 = Control center OR Home gesture? 
       //     This method is called twice, first with '2' then with '6'. I 
       //     am currently assuming that this '2' is related to home gesture
       //     and the '6' is the proper control center. Only using '2' did
       //     not prevent the CC showing up, which is why I use '6' instead.
       // 6 = Control center 2 - This method is called twice, second with '2'
       
       // iOS 11 - iPhone X (testing with 'fake iPhoneX' tweak 'LittleX')
       //          only on an iPhone SE (11.0.3)
       // ===============================================================
       // 1 = A) Notification center (swipe down on left side of 'notch')
       //     B) Control center (swipe down on right side of 'notch')
       // 2 = From bottom, after '20'
       // 6 = Control center - This method is called after '1' when swiping
       //     on the right side of the notch.
       // 20 = Home gesture AND Horizontal left/right swipe on the new 
       //      grabber to switch between apps easily
       //
       // Note: With LittleX neither '1 B' nor '6' works, however since
       //       the CC still comes up from the bottom, since it's not a
       //       real iPhone X, I think this might be a bug so I will ignore
       //       it for now and hope it works on real X devices.
       
       // iOS 10 (Tested on 10.2 only)
       // ===============================================================
       // 1 = Notification center
       // 3 = Control center
       
       // iOS 9 - iPhone (9.0.2)
       // ===============================================================
       // 1 = Notification center
       // 3 = Control center
       
       // iOS 9 - iPad (9.3.3)
       // ===============================================================
       // 1 = Notification center
       // 3 = Control center
       // 6 = Related to the 4/5 finger swipe to change apps I think.
       // 7 = Pre-Notification center + Pre-Control center + 4 finger touch?
       //     7 is both called before the NC and the CC. In the case of the CC, the 
       //     order this method is called in is 7-7-3. Still not sure what the '7' is.
       //     This is also appearing a lot when we do 4 finger touch to fast-switch apps.
       //     A possibility is that this is just "any touch". Since it appears multiple 
       //     times when doing the 4/5 finger swipe (see '6'). But who knows.
       // 8 = Pre-Notification center
       //     When swiping from the top area in iOS 9 (maybe others) this method is
       //     called 3 times before finally calling the '1' (NC). In this order:
       //     7-7-8-1. I am not sure what they are, but to prevent the NC from 
       //     appearing we can simply just look for the '1' which is more or less
       //     confirmed to be the NC.
       
       // iOS 8 and below
       // ===============================================================
       // This class does not exist in iOS 8 and below.
       // TODO: Make sure iOS 6, 7 and 8 also can prevent CC/NC
       
       if (type == 1 || type == 6 || type == 3 || type == 20) {
               return NO;
       }
       
       return %orig();
   }
   
   %end

Here are some enums that the numbers actually mean.

   SBSystemGestureTypeNone = 0,
   SBSystemGestureTypeShowNotificationCenter,
   SBSystemGestureTypeDismissBanner,
   SBSystemGestureTypeShowControlCenter,
   SBSystemGestureTypeSuspendApp,
   SBSystemGestureTypeSwitcherSlideUp,
   SBSystemGestureTypeSwitchApp,
   SBSystemGestureTypeSceneResize,
   SBSystemGestureTypeSideAppReveal,
   SBSystemGestureTypeSideAppGrabberReveal,
   SBSystemGestureTypeSideAppOverlayDismiss,
   SBSystemGestureTypeSideSwitcherReveal,
   SBSystemGestureTypeSideSwitcherGrabberPress,
   SBSystemGestureTypeSwitcherForcePress,
   SBSystemGestureTypeDismissCarPlayBanner

Quote regarding iOS 7/8

   "and for iOS 7/8 this stuff lived in SBUIController https://github.com/thomasfinch/iOS-7-SpringBoard-Headers/blob/master/SBUIController.h#L166 (edited)" 


Again for iOS 7/8 you could use the below one as well. If you don't use the one from the GitHub link.

Someone should confirm this, but it is what I use in 'Snapper 2' and it didn't show the CC NC so..

   %hook SBUIController
   
   // I guess this one prevents the CC and NC from appearing in iOS 8? (and 7?)
   // But for above, we need to do the (see below)
   - (BOOL)shouldSendTouchesToSystemGestures {
           return NO;
   }
   
   %end

Alternative ways to prevent the Home gesture in iOS 11 on iPhone X are

   //
   // Disables the 'Home Gesture' on iPhone X (starting at iOS 11)
   // NOTE: If we have issues with the horizontal iPhone X app switching gesture
   // maybe look into "_handleDeckSwitcherPanGesture:" in "SBFluidSwitcherGestureManager"
   // which the -[SBGrabber shouldBeginTouch] (?) needs to be off from.
   //
   %hook SBHomeGestureSettings
   
   - (BOOL)isHomeGestureEnabled {
        return NO;
   }
   
   %end 

And

   %hook SBFluidSwitcherGestureManager
   
   - (BOOL)_shouldBeginBottomEdgePanGesture:(id)arg1 {
       return NO;
   }
   
   %end