From 404f19037ec0735e0423e7570dd914be4667697b Mon Sep 17 00:00:00 2001 From: "E.B" <57380422@qq.com> Date: Wed, 20 Apr 2016 09:59:04 +0800 Subject: [PATCH] iOS - update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.更新手动安装文档 2.fix 影响其他插件使用的 bug --- API/iOS_install.md | 26 +++++++++++++------------- README.md | 4 ++-- src/ios/Plugins/AppDelegate+JPush.m | 29 +++++++++++++++++++---------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/API/iOS_install.md b/API/iOS_install.md index 3d38664..b445c30 100644 --- a/API/iOS_install.md +++ b/API/iOS_install.md @@ -1,12 +1,12 @@ -### iOS手动安装 +### iOS 手动安装 -下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR` +- 下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR` +- 用 xcode 打开 iOS 工程 将 `$JPUSH_PLUGIN_DIR`/src/ios/Plugins/ 拖到 project 中 -1. 用 xcode 打开 iOS 工程 将 `$JPUSH_PLUGIN_DIR`/src/ios/Plugins/ 拖到 project 中 -2. 将 `$JPUSH_PLUGIN_DIR`/src/ios/lib/ 拖到 project 中 +- 将 `$JPUSH_PLUGIN_DIR`/src/ios/lib/ 拖到 project 中 -4. 添加以下框架,打开 xcode,点击 project,选择(Target -> Build Phases -> Link Binary With Libraries) +- 添加以下框架,打开 xcode,点击 project,选择(Target -> Build Phases -> Link Binary With Libraries) CFNetwork.framework CoreFoundation.framework @@ -17,16 +17,16 @@ UIKit.framework -5. 在你的工程中创建一个新的 Property List 文件 +- 在你的工程中创建一个新的 Property List 文件 并将其命名为 PushConfig.plist,填入 Portal 为你的应用提供的 APP_KEY 等参数 -10. 在 AppDelegate.m 中包含头文件 +- 在 AppDelegate.m 中包含头文件 #import "JPUSHService.h" #import "JPushPlugin.h" -6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能 +- 在 AppDelegate.m 中的下列方法中添加代码,如果方法不存在则增加相应方法与内容 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ //原内容保持不变 @@ -43,11 +43,10 @@ //原内容保持不变 // Required add [JPUSHService handleRemoteNotification:userInfo]; - [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification - object:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo]; } -7. 修改 phonegap config.xml 文件用来包含 Plugin/ 内的插件 +- 修改 phonegap config.xml 文件用来包含 Plugin/ 内的插件 @@ -56,7 +55,8 @@ -8. 复制 `$JPUSH_PLUGIN_DIR`/www/PushNotification.js 到工程的 www 目录下面 -9. 在需要使用插件处加入 +- 复制 `$JPUSH_PLUGIN_DIR`/www/JPushPlugin.js 到工程的 www 目录下面 + +- 在需要使用插件处加入 diff --git a/README.md b/README.md index e5f90d8..bd992e5 100644 --- a/README.md +++ b/README.md @@ -65,12 +65,12 @@ JPush-PhoneGap-Plugin 支持 iOS, Android 的推送插件。 ### Android 手动安装 -[Android 手动安装文档地址](document/Android_handle_install.md) +[Android 手动安装文档地址](API/Android_handle_install.md) ### iOS 手动安装 -[IOS手动安装文档地址](document/iOS_handle_install.md) +[IOS 手动安装文档地址](API/iOS_install.md) ###示例 diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index 5bee122..207a3d0 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -9,20 +9,29 @@ #import "AppDelegate+JPush.h" #import "JPushPlugin.h" #import "JPUSHService.h" +#import @implementation AppDelegate (JPush) --(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ - [JPushPlugin setLaunchOptions:launchOptions]; ++(void)load{ - //cordova didFinishLaunchingWithOptions - CGRect screenBounds = [[UIScreen mainScreen] bounds]; - self.window = [[UIWindow alloc] initWithFrame:screenBounds]; - self.viewController = [[CDVViewController alloc] init]; - self.window.rootViewController = self.viewController; - self.window.autoresizesSubviews = YES; - [self.window makeKeyAndVisible]; - return YES; + 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 {