jdg / MBProgressHUD

MBProgressHUD + Customizations
http://www.bukovinski.com/
MIT License
16.01k stars 3.56k forks source link

'UIApplicationDidChangeStatusBarOrientationNotification' is deprecated: first deprecated in iOS 13.0 - Use viewWillTransitionToSize:withTransitionCoordinator: instead. #606

Open trhtkv opened 4 years ago

trhtkv commented 4 years ago

'UIApplicationDidChangeStatusBarOrientationNotification' is deprecated: first deprecated in iOS 13.0 - Use viewWillTransitionToSize:withTransitionCoordinator: instead.

PaulSolt commented 7 months ago

I think you can update this to use the notification: UIDeviceOrientationDidChangeNotification instead of UIApplicationDidChangeStatusBarOrientationNotification

This code file is a UIView, so it won't have access to viewWillTransitionToSize:withTransitionCoordinator which is a UIViewController method.

I tested making that change in an old app, and it appears to be ok at suppressing the warning and logic still seems to be ok with a quick test.

An alternative would be to expose a new method that you'd have to tie into your UIViewController callback, which seems more cumbersome.

PaulSolt commented 7 months ago

Another option is to remove all this logic, as I don't think you really want it rotating anymore on modern iOS.

- (void)registerForNotifications {
#if !TARGET_OS_TV && !TARGET_OS_MACCATALYST
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

    [nc addObserver:self selector:@selector(statusBarOrientationDidChange:)
               name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}

- (void)unregisterFromNotifications {
#if !TARGET_OS_TV && !TARGET_OS_MACCATALYST
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
#endif
}

#if !TARGET_OS_TV && !TARGET_OS_MACCATALYST
- (void)statusBarOrientationDidChange:(NSNotification *)notification {
    UIView *superview = self.superview;
    if (!superview) {
        return;
    } else {
        [self updateForCurrentOrientationAnimated:YES];
    }
}
#endif