开发者

iPhone: I've come up with an interesting way I could get around an API limitation. Will this work?

The problem that I'm trying to solve is this:

When using a UIImagePicker, it adjusts itself as the device is rotated. I don't want it to do this, rather it should constantly stay in the portrait orientation. I've googled aplenty and haven't found any solution (just others with the same unsolved problem). The only answer was to use a private API call, I would rather not risk doing this.

-

However, I came across 'method swizzling' - a way of swapping method names at runtime. What I'm planning to do:

  • Add a category to UIViewController that defines a methods such as 'customShouldRotate' defining custom behavior that won't allow rotation.

  • Swizzle these methods with the default rotation methods of UIViewController at runtime.

-

After a bit of thought though, it might not be that simple. Here's why - any answers to the following would be much appreciated.

  • The method I'm swizzling is in UIViewController, not UIImagePickerController. I can't swizzle in the image picker directly, I've alr开发者_JAVA技巧eady tried via subclassing and it appears to be a subview's controller that's handling the rotation rather than UIImagePickerController itself. Will swizzled methods pass down to subclasses, if not then is there a workaround to do this?

  • It may not be a normal rotation method from UIViewController that is being used in UIImagePickerController. Is there any way to tell?

  • Will Apple be OK with method swizzling? I'm not using a private API call, but then again I wouldn't be overly surprised if they rejected it anyway.

-

Is this whole idea feasible/worth trying - or, if someone's actually solved the original problem in a different manner then that would be even better.


Method swizzling is fine: Apple check for private APIs using a static analyzer. If you can overload, swizzle, or do what you will to achieve the same effect without calling a private API it won't be picked up by the analyzer.

The only reason Apple may reject you for is for modifying 'standard' behaviour - but I suspect this won't happen. The worst thing is your app gets kicked back to you and you have to reinstate the original behaviour.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜