I submitted my app a little over a week ago and got the dreaded rejection email today. It tells me that my app cannot be accepted because I'm using a non-public API; specifically, it says,
The non-public API that is included in your application is firstResponder.
Now, the offending API call is actually a solution I found here on SO:
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView *firstResponder = [keyWindow performSelector:@selector(firstResponder)];
How do I get the current first responder on the screen? I'm looking for a way that won't get my app rejected.
This is what I did to find what UITextField is the firstResponder when the user clicks Save/Cancel in a ModalViewController:
I have a slightly different approach than most here. Rather than iterate through the collection of views looking for the one that has
isFirstResponder
set, I too send a message tonil
, but I store the receiver (if any), then return that value so the caller gets the actual instance (again, if any).I can then resign the first responder, if any, by doing this...
But I can now also do this...
Using Swift and with a specific
UIView
object this might help:Just place it in your
UIViewController
and use it like this:Take note that the result is an Optional value so it will be nil in case no firstResponser was found in the given views subviews.
This is what I have in my UIViewController Category. Useful for many things, including getting first responder. Blocks are great!
This is good candidate for recursion! No need to add a category to UIView.
Usage (from your view controller):
Code:
you can call privite api like this ,apple ignore: