问题描述
我在一个多星期前提交了我的应用程式,今天收到了可怕的拒绝电子邮件。它告诉我,我的应用程序不能被接受,因为我使用非公共API;具体来说,
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,
现在,冒犯的API调用实际上是我在SO上找到的解决方案:
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.
推荐答案
在我的一个应用程序中,我经常想要的是第一响应者如果用户在背景上轻敲则辞职。为此,我在UIView上写了一个类别,我在UIWindow上调用。
In one of my applications I often want the first responder to resign if the user taps on the background. For this purpose I wrote a category on UIView, which I call on the UIWindow.
下面是基于这个,应该返回第一个响应者。
The following is based on that and should return the first responder.
@implementation UIView (FindFirstResponder)
- (id)findFirstResponder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.subviews) {
id responder = [subView findFirstResponder];
if (responder) return responder;
}
return nil;
}
@end
iOS 7+
- (id)findFirstResponder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.view.subviews) {
if ([subView isFirstResponder]) {
return subView;
}
}
return nil;
}
这篇关于获取当前的第一个响应者,而不使用私有API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!