iOS - 修复因cordova版本不同导致的bug

1.因低版本cordova中AppDelegate继承自NSObject导致找不到 super
didFinishLaunchingWithOptions的问题。
This commit is contained in:
E.B 2016-03-14 17:26:53 +08:00
parent 40c98f4f04
commit 3868e0be35

View File

@ -9,12 +9,30 @@
#import "AppDelegate+JPush.h"
#import "JPushPlugin.h"
#import "JPUSHService.h"
#import <objc/runtime.h>
@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 {