iOS-优化代码

1.AppDelegate+JPush.m中不再使用runtime
This commit is contained in:
E.B 2016-03-21 15:30:16 +08:00
parent a9f5fc45bd
commit c2babc3a39

View File

@ -9,30 +9,20 @@
#import "AppDelegate+JPush.h" #import "AppDelegate+JPush.h"
#import "JPushPlugin.h" #import "JPushPlugin.h"
#import "JPUSHService.h" #import "JPUSHService.h"
#import <objc/runtime.h>
@implementation AppDelegate (JPush) @implementation AppDelegate (JPush)
+(void)load{ -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
Method origin; [JPushPlugin setLaunchOptions:launchOptions];
Method swizzle;
origin=class_getInstanceMethod([self class],@selector(init));
swizzle=class_getInstanceMethod([self class], @selector(init_plus));
method_exchangeImplementations(origin, swizzle);
}
-(instancetype)init_plus{ //cordova didFinishLaunchingWithOptions
[[NSNotificationCenter defaultCenter] addObserver:self CGRect screenBounds = [[UIScreen mainScreen] bounds];
selector:@selector(applicationDidLaunch:) self.window = [[UIWindow alloc] initWithFrame:screenBounds];
name:@"UIApplicationDidFinishLaunchingNotification" self.viewController = [[CDVViewController alloc] init];
object:nil]; self.window.rootViewController = self.viewController;
return [self init_plus]; self.window.autoresizesSubviews = YES;
} [self.window makeKeyAndVisible];
return YES;
-(void)applicationDidLaunch:(NSNotification*)notification{
if (notification) {
[JPushPlugin setLaunchOptions:notification.userInfo];
}
} }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {