From f624670b4fcdb82986e380095294059aa665e4eb Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Mon, 3 Aug 2015 13:34:36 +0800 Subject: [PATCH] fix #62 --- plugin.xml | 4 +- src/ios/Plugins/AppDelegate+JPush.h | 15 ++++++ src/ios/Plugins/AppDelegate+JPush.m | 74 +++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/ios/Plugins/AppDelegate+JPush.h create mode 100644 src/ios/Plugins/AppDelegate+JPush.m diff --git a/plugin.xml b/plugin.xml index 05a5cbb..8abab10 100644 --- a/plugin.xml +++ b/plugin.xml @@ -30,9 +30,9 @@ - + + - diff --git a/src/ios/Plugins/AppDelegate+JPush.h b/src/ios/Plugins/AppDelegate+JPush.h new file mode 100644 index 0000000..3694db5 --- /dev/null +++ b/src/ios/Plugins/AppDelegate+JPush.h @@ -0,0 +1,15 @@ +// +// AppDelegate+JPush.h +// delegateExtention +// +// Created by 张庆贺 on 15/8/3. +// Copyright (c) 2015年 JPush. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate (JPush) + +//@property(nonatomic,strong)NSDictionary *luanchOption; + +@end diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m new file mode 100644 index 0000000..2ae00e5 --- /dev/null +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -0,0 +1,74 @@ +// +// AppDelegate+JPush.m +// delegateExtention +// +// Created by 张庆贺 on 15/8/3. +// Copyright (c) 2015年 JPush. All rights reserved. +// + +#import "AppDelegate+JPush.h" +#import +#import "JPushPlugin.h" +#import "APService.h" + +static char launchNotificationKey; + +@implementation AppDelegate (JPush) + ++(void)load{ + + Method origin; + Method swizzle; + + origin=class_getClassMethod([self class],@selector(init)); + swizzle=class_getClassMethod([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 { + [APService registerDeviceToken:deviceToken]; +} +-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ + + [APService handleRemoteNotification:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification + object:userInfo]; + +} +-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ + + [APService handleRemoteNotification:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification + object:userInfo]; + + +} + +//delegate里不能声明变量,所以采用关联对象这种技术绕过这个限制 +//-(NSDictionary *)luanchOption{ +// return objc_getAssociatedObject(self, &launchNotificationKey); +//} +//-(void)setLuanchOption:(NSDictionary *)luanchOption{ +// objc_setAssociatedObject(self, &launchNotificationKey, luanchOption, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +//} +//-(void)dealloc{ +// self.luanchOption=nil; +//} + +@end