简体   繁体   中英

private method in 3rd party iOS library

I'd like to use a popover view for iPhone. I found a 3rd party library and author says some of its method is utilizing a private method.(which will cause problem when submitting to app store)
But I don't see where is private method being used in his code.
Can you spot them?

[barButtonItem performSelector:@selector(view)] is considered to be calling a private method?

https://github.com/sonsongithub/PopupView/blob/master/SNPopupView%2BUsingPrivateMethod.m

- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {

        if(![barButtonItem respondsToSelector:@selector(view)]) {
            // error
            return;
        }

    UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];
    UIView *targetSuperview = [targetView superview];

    BOOL isOnNavigationBar = YES;

    if ([targetSuperview isKindOfClass:[UINavigationBar class]]) {
        isOnNavigationBar = YES;
    }
    else if ([targetSuperview isKindOfClass:[UIToolbar class]]) {
        isOnNavigationBar = NO;
    }
    else {
        // error
        return;
    }

    CGRect rect = [targetSuperview convertRect:targetView.frame toView:inView];

    CGPoint p;
    p.x = rect.origin.x + (int)rect.size.width/2;

    if (isOnNavigationBar)
        p.y = rect.origin.y + rect.size.height + BAR_BUTTON_ITEM_UPPER_MARGIN;
    else
        p.y = rect.origin.y - BAR_BUTTON_ITEM_BOTTOM_MARGIN;

    [self showAtPoint:p inView:inView animated:animated];
}

view is not the public property of UIBarButtonItem. And reference application is using it.

To validate any such feature, it is preferrable to call its properties using dot operator or using it's getter (which is the same thing).

Check this code, which indicates it is private:

UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];

It is accessing view with performSelector, and XCode is not smart enough to give any warning, while using private properties in these ways.

From my experience, when you go to upload an image, Apple runs some automated checks against your binary. So why not just try an upload and see if they complain? I got bit once by an included library using a method on their own class that was the same names as some private method in an Apple class, and my app didn't make it through the gate due to that (I just renamed that method since I had the source.)

You're not supposed to access the view property of a UIBarButtonItem . That's where the private call is:

if(![barButtonItem respondsToSelector:@selector(view)]) {
    // error
    return;
}

UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];

See the official doc for UIBarButtonItem , it has no public view property.

Though, it's not really a private call as the view method is perfectly legal and will not trigger some alert (like if you used a method name that's only used by private calls), so Apple shouldn't notice it. But I only said shouldn't , not won't .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM