问题
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