ShareKit method swizzling in Lion / Xcode 4.3.1?

2019-05-26 14:43发布

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?

2条回答
SAY GOODBYE
2楼-- · 2019-05-26 14:52

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).

查看更多
Luminary・发光体
3楼-- · 2019-05-26 15:03

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.

查看更多
登录 后发表回答