这是否被视为在 iPhone 开发中使用私有函数,从而非法?
我正在尝试禁用 UIWebView
的滚动,而我发现的唯一方法是使用这种方式:
#import <objc/runtime.h>
id scroller = [[Webview subviews] lastObject];
int count;
Method *method = class_copyMethodList([scroller class], &count);
int i;
for (i=0; i<count; i++) {
if (strcmp(method_getName(method[i]), "setScrollingEnabled:") == 0)
break;
}
IMP test = method_getImplementation(method[i]);
test(scroller, @selector(setScrollingEnabled:), NO);
Is this isn't think is be an invalid way of using the iPhone SDK?这会导致我的应用程序被 App Store 拒绝吗?
I'm trying to disable scrolling for a UIWebView
and the only way I found is using this way:
#import <objc/runtime.h>
id scroller = [[Webview subviews] lastObject];
int count;
Method *method = class_copyMethodList([scroller class], &count);
int i;
for (i=0; i<count; i++) {
if (strcmp(method_getName(method[i]), "setScrollingEnabled:") == 0)
break;
}
IMP test = method_getImplementation(method[i]);
test(scroller, @selector(setScrollingEnabled:), NO);
Is this considered to be an illegal way of using the iPhone SDK? Can this cause my application to be rejected for the App store?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这样做不是更简单吗:
if ([scroller respondsToSelector: @selector(setScrollingEnabled:)]) [scroller setScrollingEnabled: NO]
这避免了他们可能扫描您的二进制文件的任何潜在方法调用(不确定他们如何验证“合法性”)。它仍然不是 100% 犹太洁食,但绝对更安全。
wouldn't it be a lot simpler to do this:
if ([scroller respondsToSelector: @selector(setScrollingEnabled:)]) [scroller setScrollingEnabled: NO]
This avoids any of the potential method calls they might scan your binary for (not sure how they verify 'legality'). It's still not 100% kosher, but definitely safer.
我刚刚因为使用 setScrollingEnabled 而被拒绝了我的应用程序,所以要小心!
他们的消息是:“您的应用程序中包含的非公共 API 是 setScrollingEnabled”
I just got my app rejected because of using setScrollingEnabled, so BEWARE!
Their message: "The non-public API that is included in your application is setScrollingEnabled"
如果该方法不在 .h 文件中,则它是私有的。这是一个非常简单的规则。事实上,您需要为简单的消息发送执行任何运行时“恶作剧”,这一事实应该很能说明问题。
If the method isn't in the .h file, it's private. It's a pretty simple rule. The fact you need to perform any runtime "shenanigans" for a simple message send should be telling.
是的,这被认为是非法的。我实际上收到了一个“警告”,说 setSCrollingEnabled 是私有框架的一部分。他们批准了该应用程序,但表示我需要在提交的下一次更新中删除此调用。
Yes this is considered illegal. I actually received a 'warning' saying that setSCrollingEnabled was part of a private framework. They approved the app but said that I needed to remove this call for the next update I submit.
这是可行的——
这解决了问题,同时还保持链接可点击、嵌入可滚动的任何滚动视图,并且仅使用公共 API。
我发现如果将 WebView 嵌入到
UIScrollView
中,JavaScript 解决方案会阻止 WebView 正常工作,并且将userInteractionEnabled
设置为 false 会阻止 webView 中的链接可点击。This works –
This fixes the problem, while also keeping the links click-able, any scrollViews it’s embedded in scrollable, and uses only public API’s.
I found that the javascript solutions prevented the WebViews from working correctly if it was embedded in a
UIScrollView
and settinguserInteractionEnabled
to false prevented links in the webView from being click-able.这可能是有问题的,但只要当/如果找不到该方法时您有后备行为,就不会成为拒绝的原因。还有更严重的虐待行为已经过去。
It might be questionable, but not a cause for rejection as long as you have a fallback behavior when/if the method can not be found. There are worse abuses that have passed.
好吧,也许他们认为您采用了另一种方式,例如获取屏幕外 UIWebView 的内容并将其显示在普通 UIIMage 视图中,或者获取页面的 HTML 内容限制其大小并将其呈现在 UIWebView 中。
Well, maybe they think you did it another way, like take the contents of an offscreen UIWebView and displayed it in a plain UIIMage view, or take the HTML content of a page restrict its size and render it in a UIWebView.