in order to prevent the MPMoviePlayerController
from displaying UIAlertView
alerts, you can use the following approach:
add the following methods to your application delegate, and make sure to call patchMPVVC
only once on startup:
#import "/usr/include/objc/objc-runtime.h"
- (void)_handleError:(NSNotification *)notification {
// do nothing, or add any custom error handling code here
}
- (void)patchMPVVC {
// add the _handleError: method to the MPVideoViewController class
Class class = NSClassFromString(@"MPVideoViewController");
Method myMethod = class_getInstanceMethod([self class], @selector(_handleError:));
class_addMethod(class, @selector(_handleError:), method_getImplementation(myMethod), "v@:@");
// swap method implementations:
SEL selector = sel_registerName("_videoView_playbackErrorNotification");
Method originalMethod = class_getInstanceMethod(class, selector);
myMethod = class_getInstanceMethod(class, @selector(_handleError:));
method_exchangeImplementations(originalMethod, myMethod);
}
just keep in mind that this code might be rejected by apple due to the fact that it references the private MPVideoViewController
class and _videoView_playbackErrorNotification
method.