简体   繁体   中英

How to disable sharing on UITextView without using non-public APIs and Rejected by apple?

My latest release to apple is rejected with following response.

Your app uses or references the following non-public APIs, which is a violation of the App Store Review Guidelines:

_share:

The use of non-public APIs is not permitted in the App Store because it can lead to a poor user experience should these APIs change.

I have thoroughly searched my app in XCode for _share: method. I am using it to disable sharing on one of UITextView like this.

@implementation UITextViewDisableShare : UITextView

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(_share:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}
@end

There are a lot of questions on stack-overflow which suggest to use above code to disable copy, paste or share options programmatically eg THIS . I only need to disable sharing option, so I can't simply set userInteractionEnabled=NO .

One of my app release is already accepted by App Store with above code in it. How should I disable Sharing on my UITextView, so that it do not conflicts with any of apple's review guide lines and non-public APIs?

Take a turn(no api of _share ):

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:) 
      || action == @selector(copy:) 
      // ... selectors that allow except _share.
    )
    {
        return YES;
    }

    return NO;
}

This concern may be unfounded, but perhaps returning NO from canPerformAction:withSender: for anything except the explicit selectors that one knows of might result in unintended consequences. For example, we know of the methods declared in UIResponderStandardEditActions but we also know there are others which aren't listed in that header such as the one that prompted the initial question; in addition, perhaps there are cases where the iOS runtime may perform other actions that are not generally known.

If you don't need to allow any of the other actions which might arise from selected text (such "Copy" or "Look up") then disallowing the actions of "select:" or "selectAll:" for your UITextField will give you the result you seek.

Swift:

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(cut(_:))
        || action == #selector(copy(_:))
        || action == #selector(select(_:))
        || action == #selector(selectAll(_:))
        || action == #selector(paste(_:))
        || action == #selector(delete(_:)) {
        return super.canPerformAction(action, withSender: sender)
    }
    return false
}

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