ShareKit method swizzling in Lion / Xcode 4.3.1?

帅比萌擦擦* 提交于 2019-12-07 18:51:27

问题


I recently upgraded to Lion and Xcode 4.3.1 with the iOS 5 SDK, and the sharing library ShareKit is broken - it used method swizzling for its email handler. Apparently Apple has banned or at least attempted to phase out method swizzling.

ShareKit imports a file </usr/include/objc/objc-class.h>, which no longer exists, and defines its own method swizzling method SHKSwizzle. It uses this to alter MFMailComposeViewController's viewDidDisappear: method as follows:

SHKSwizzle([MFMailComposeViewController class], @selector(viewDidDisappear:), @selector(SHKviewDidDisappear:));

What do you think is the best and easiest way to work around this?


回答1:


I have never experienced method swizzling related errors on even on newest XCode and iOS SDK. I use ShareKit 2.0. Though method swizzling is a thing to be avoided in my opinion.

The method swizzled is viewDidDisappear if I remember well. Look what it does. On iOS 5 you can achieve the same using completion block in - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion.

Just change the way you dismiss the viewController in - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error might be enough.

This is just an idea, how you might get rid of method swizzle.




回答2:


The swizzling is only being used for email sharing. Use MFMailComposeViewController yourself, and strip the swizzling code out of ShareKit (it's in SHK.m).



来源:https://stackoverflow.com/questions/9900189/sharekit-method-swizzling-in-lion-xcode-4-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!