IPhone: I came up with an interesting way to overcome the limitations of the API. Will this work?

The problem I'm trying to solve is this:

When using UIImagePicker, it is configured when the device rotates. I do not want this to be done, but should always remain in portrait orientation. I googled a lot and did not find any solution (just others with the same unsolved problem). The only answer was to use a private API request, I would not risk doing this.

-

However, I came across a โ€œ swizzling method โ€ - a way to exchange method names at runtime. What I plan to do:

  • Add a category to the UIViewController that defines methods, such as customShouldRotate, that define custom behavior that will not allow rotation.

  • Prompt these methods with the default rotation methods for the UIViewController at runtime.

-

After a little thought, perhaps this is not so simple. That is why - any answers to the following would be greatly appreciated.

  • The method that I run is in the UIViewController, not the UIImagePickerController. I canโ€™t select on the image collector myself, I have already tried through a subclass and it looks like this is a spy controller that handles the rotation, and not the UIImagePickerController itself. Will swizzled methods go to subclasses, if not, is there a workaround for this?

  • This cannot be the usual rotation method from the UIViewController that is used in the UIImagePickerController. Is there any way to tell?

  • Will Apple be ok with swizzling? I do not use a private API call, but then I would not be too surprised if they refused anyway.

-

Whether the whole idea is acceptable / worth a try - or if someone really solved the original problem differently, it will be even better.

+4
source share
1 answer

The swizzling method is fine: Apple validates private APIs using a static analyzer. If you can overload, swizzle or do what you want to achieve the same effect without calling a private API, it will not be picked up by the analyzer.

The only reason Apple could reject you is to change the standard behavior, but I suspect that this will not happen. The worst thing is that your application gets back from you and you need to restore the original behavior.

0
source

Source: https://habr.com/ru/post/1344564/


All Articles