diff --git a/msext/AppDelegate.m b/msext/AppDelegate.m index 587c302..c149af1 100755 --- a/msext/AppDelegate.m +++ b/msext/AppDelegate.m @@ -21,6 +21,7 @@ #import "JANALYTICSService.h" #import "XianliaoApiManager.h" #import "QQShareManager.h" +#import @interface AppDelegate () { BOOL flag; @@ -397,3 +398,43 @@ } @end + +@interface UIApplication (FixOpenURL) +@end + +@implementation UIApplication (FixOpenURL) + ++ (void)load { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + if (@available(iOS 10.0, *)) { + Class class = [self class]; + + SEL originalSelector = @selector(openURL:); + SEL swizzledSelector = @selector(fixed_openURL:); + + Method originalMethod = class_getInstanceMethod(class, originalSelector); + Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); + + if (class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) { + class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); + } else { + method_exchangeImplementations(originalMethod, swizzledMethod); + } + } + }); +} + +- (BOOL)fixed_openURL:(NSURL*)url { + if (@available(iOS 10.0, *)) { + if ([self canOpenURL:url]) { + [self openURL:url options:@{} completionHandler:nil]; + return YES; + } + return NO; + } else { + return [self fixed_openURL:url]; + } +} + +@end