-
Notifications
You must be signed in to change notification settings - Fork 181
Safe to use Private Property for LongPress? #39
Comments
I have used this library for several production apps, and never had any issues with it. Accessing hidden properties from objects isn't really that illegal; I've never had any app rejected because of doing it at least. |
Thanks for the heads up! That's what I hoped to hear, so thanks for the confirmation :) For other people stumbling upon this thread: After years I never jumped into the water of accessing private APIs, sub-classing and in ObjC days sometimes method swizzling were all I needed. But at some point, like detecting long-press on a UIBarButtonItem for back/forward history, you have to rethink if there is another way. Welcome to the dark side ;) Your solution uses KVO to access the view, which is probably the most elegant approach. For reference this post titled "Five Pieces of Evidence for "It's Not Private" on SO sums it up, why I might not be that "illegal":
One could argue if this approach needs more work when speaking of the current implementation in DZNWebViewController, like observing the KV for view and re-inject the gesture recognizer as Yar pointed out on SO, but currently the only thing that would happend without is, that the gesture would simply not work. Nothing spectacular. @dzenbot Thanks for the nice solution! |
Mind that I answered it like three years ago and the Apple policy on that changed. Still, I guess the code in here is reasonably safe. |
@farcaller Thanks for joining! Absolutely, many things have changed. But agreed, the approach taken is still valid. If someone is really picky about: with Swift 2 a simple do-try-catch sandwich around the exchange will ensure that accessing this private View has no consequences if Apple decides to make some changes in future. |
Nothing swift-specific there, you can have |
Right, I'd been working through the changes of Swift 2 in the past days, and mixed that up. That's probably because the ObjC Anyway the exception handling changed when compared to objc. |
I guess we could do something like this instead:
This way, we're 100% sure we're dealing with an I personally avoid |
@dzenbot Fully agreed regarding the best approach where available. But I am pretty sure that isKindOfClass would not work here: The UIBarButtonItems do not subclass UIView. They are subclassed from > UIBarItem > NSObject. The UIView is just a private (Sub-)View of the Buttons that's inaccessible without KVO or iterating through the Views. So the current approach seems still to be the best. |
This check is not for the |
That |
Both is right. KVO came from having my current KVO code for WKWebView in mind. Ok, time to get some sleep, it's in the middle of the night here ;) |
In configureBarItemsGestures you are accessing the private View property of the UIBarButtonItems. Seems to be the best way due to the lack of UIBarButtonItems exposing their gesture Recognizers.
Are you aware of any App Store rejections caused by this?
The text was updated successfully, but these errors were encountered: