iOS 13.4 & Xcode 11.4 Pit Small note (rewriting system get)

Recently updated the new system, we found UIModalPresentationFullScreen Modal style settings ineffective .

I believe we adaptation iOS13 the system, to adapt Modal default style changes (default before iOS13 after UIModalPresentationFullScreen 13 to become UIModalPresentationAutomatic) a lot of people are achieved through classification.

Namely: to extend the UIViewController method (essentially get overridden method modalPresentationStyle property), so all the places directly in force, not a modified one, of course, private pod library or to their own modifications.

/*
 Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
 If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but system-provided subclasses may resolve UIModalPresentationAutomatic to other concrete presentation styles. Participation in the resolution of UIModalPresentationAutomatic is reserved for system-provided view controllers.
 Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
 */
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));

 

// adaptation iOS13 
- (UIModalPresentationStyle) modalPresentationStyle {
    //     adapted RN pop contents iOS13 system is blocked 
    IF ([Self The isKindOfClass: NSClassFromString ( @ " RCTModalHostViewController " )]) {
         return UIModalPresentationOverCurrentContext; 
    } the else {
         return UIModalPresentationFullScreen; 
    } 
}

Then the question is, classification - (UIModalPresentationStyle) modalPresentationStyle this method in Xcode 11.4 & iOS 13.4 environment is no longer carried out.

So far to find the root cause of the problem is  Xcode 11.4 & under iOS 13.4 Environmental classification system-level attributes override the get method will fail . Normal system-level approach (such as :( void ) viewWillAppear :( BOOL ) Animated; rewrite) will still call.

Solution:

1, the use of low version of Xcode package

2, an alternative approach using runtime (or system calls this method, but we no longer call the get method overridden, so alternative methods to achieve)

+ (void)swizzleInstanceSelector:(SEL)originalSelector withSelector:(SEL)swizzledSelector
{
    Class class = [self class];
    
    Method originalMethod = class_getInstanceMethod(class, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
    
    BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
    if (success)
    {
        class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
    }
    else
    {
        method_exchangeImplementations(originalMethod, swizzledMethod);
    }
}

+ (void)load
{    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
         [self swizzleInstanceSelector:@selector(modalPresentationStyle) withSelector:@selector(uiviewController_modalPresentationStyle)];
    });
}

- (UIModalPresentationStyle)uiviewController_modalPresentationStyle
{
   //    适配iOS13系统下 RN弹窗内容被遮挡
    if ([self isKindOfClass:NSClassFromString(@"RCTModalHostViewController")]) {
        return UIModalPresentationOverCurrentContext;
    } else {
        return UIModalPresentationFullScreen;
    }
}

expand:

get method of rewriting system attributes may be affected

Guess you like

Origin www.cnblogs.com/lijianyi/p/12607377.html
Recommended