From 3868e0be3524b81dde79d0605a1bf066d520e84e Mon Sep 17 00:00:00 2001 From: "E.B" <57380422@qq.com> Date: Mon, 14 Mar 2016 17:26:53 +0800 Subject: [PATCH] =?UTF-8?q?iOS=20-=20=E4=BF=AE=E5=A4=8D=E5=9B=A0cordova?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=8D=E5=90=8C=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.因低版本cordova中AppDelegate继承自NSObject导致找不到 super didFinishLaunchingWithOptions的问题。 --- src/ios/Plugins/AppDelegate+JPush.m | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index 542ea00..b52c0ba 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -9,12 +9,30 @@ #import "AppDelegate+JPush.h" #import "JPushPlugin.h" #import "JPUSHService.h" +#import @implementation AppDelegate (JPush) --(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ - [JPushPlugin setLaunchOptions:launchOptions]; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; ++(void)load{ + Method origin; + Method swizzle; + origin=class_getInstanceMethod([self class],@selector(init)); + swizzle=class_getInstanceMethod([self class], @selector(init_plus)); + method_exchangeImplementations(origin, swizzle); +} + +-(instancetype)init_plus{ + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationDidLaunch:) + name:@"UIApplicationDidFinishLaunchingNotification" + object:nil]; + return [self init_plus]; +} + +-(void)applicationDidLaunch:(NSNotification*)notification{ + if (notification) { + [JPushPlugin setLaunchOptions:notification.userInfo]; + } } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {