From f0c63744090aec78a5018da773cdfb94a329d964 Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Tue, 14 Apr 2015 11:21:09 +0800 Subject: [PATCH] fix Cordova CLI auto install in document --- README.md | 93 +++++++++++++++--------------- document/Android_handle_install.md | 12 ++-- document/iOS_handle_install.md | 50 +++++++--------- 3 files changed, 72 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 49ee46c..cb68968 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ ## JPush PhoneGap Plugin ## -###创建项目### + + +###准备工作 + 1. cordova create 文件夹名字 包名 应用名字 cordova create Myproj com.myproj.jpush MyTestProj @@ -13,67 +16,62 @@ ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`, 然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加 -### Android使用PhoneGap/Cordova CLI自动安装 -1. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR` +###Cordova CLI/Phonegap 安装 Android & iOS + +3. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR` git clone https://github.com/jpush/jpush-phonegap-plugin.git - -2. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407) + + +4. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407) -3. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest) +5. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest) -4. cordova cli 添加jpush phonegap插件和依赖的device插件: +6. cordova cli 添加jpush phonegap插件和依赖的device插件: cordova plugin add $JPUSH_PLUGIN_DIR cordova plugin add org.apache.cordova.device +7. iOS添加初始化JPush sdk代码 如果你要先部署android平台,可以先忽略这一步,当需要iOS 平台时,只加上这个步骤即可 + + + 用xcode 打开 Myproj下的iOS工程 + + 打开xcode右边工程目录下`Resources/PushConfig.plist` + + 在APP_KEY和CHANNLE字段 分别添加您的appkey和channle + + + 打开xcode右边工程目录下`AppDelegate.m`,包含以下头文件 -5. 在js中调用函数,初始化jpush sdk + #import "APService.h" + #import "JPushPlugin.h" - window.plugins.jPushPlugin.init(); - window.plugins.jPushPlugin.setDebugMode(true); + + 在AppDelegate.m文件中,添加JPush SDK 提供的 API 来实现功能 + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ + //原内容保持不变 + //Required add + [JPushPlugin setLaunchOptions:launchOptions]; + return YES; + } + - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + //原内容保持不变 + // Required add + [APService registerDeviceToken:deviceToken]; + } + - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { + //原内容保持不变 + // Required + [APService handleRemoteNotification:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification + object:userInfo]; + } + +7. 在js中调用函数,初始化jpush sdk -###IOS使用PhoneGap/Cordova CLI自动安装 - -1. 使用PhoneGap/Cordova CLI添加jpush phonegap插件和依赖的device插件 - - cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git - cordova plugin add org.apache.cordova.device - -3. 修改Resources/PushConfig.plist文件 - - + 在APP_KEY和CHANNLE字段 分别添加您的appkey和channle - -4. 在AppDelegate.m中包含头文件 - - #import "APService.h" - #import "JPushPlugin.h" - -5. 在AppDelegate.m文件中,添加JPush SDK 提供的 API 来实现功能 - - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ - //原内容保持不变 - //Required add - [JPushPlugin setLaunchOptions:launchOptions]; - return YES; - } - - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - //原内容保持不变 - // Required add - [APService registerDeviceToken:deviceToken]; - } - - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - //原内容保持不变 - // Required - [APService handleRemoteNotification:userInfo]; - [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification - object:userInfo]; - } + window.plugins.jPushPlugin.init(); ### Android 手工安装 @@ -94,6 +92,7 @@ src/ios/example/js/* to www/js ###关于'phonegap build'云服务 + 该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包 ###常见错误 @@ -133,7 +132,6 @@ event - jpush.openNotification + 获取自定义消息推送内容 - window.plugins.jPushPlugin.receiveMessageIniOSCallback(data) + 页面的统计 @@ -177,7 +175,6 @@ + 统计分析 API onResume / onPause(java api) - + 清除通知 API diff --git a/document/Android_handle_install.md b/document/Android_handle_install.md index 68ae2d3..ea9b1c1 100644 --- a/document/Android_handle_install.md +++ b/document/Android_handle_install.md @@ -1,10 +1,12 @@ #Android 手工安装 -1. 复制src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下) -2. 复制src/android/armeabi/libjpush.so 到lib/armeabi/ -3. 复制src/android/jpush-sdk-release1.5.0.jar 到lib/ -4. 复制src/android/test_notification_layout.xml到res/layout/ -5. 复制src/android/jpush_notification_icon.png 到res/drawable/ +下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR` + +1. 复制:`$JPUSH_PLUGIN_DIR`/src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下) +2. 复制:`$JPUSH_PLUGIN_DIR`/src/android/armeabi/libjpush.so 到lib/armeabi/ +3. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush-sdk-release1.5.0.jar 到lib/ +4. 复制:`$JPUSH_PLUGIN_DIR`/src/android/test_notification_layout.xml到res/layout/ +5. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush_notification_icon.png 到res/drawable/ 6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限 diff --git a/document/iOS_handle_install.md b/document/iOS_handle_install.md index 48ae36c..00e88a1 100644 --- a/document/iOS_handle_install.md +++ b/document/iOS_handle_install.md @@ -1,12 +1,12 @@ ### IOS手工安装 -1. 添加src/ios/Plugins/到project中 -2. 添加src/ios/lib/到project中 -3. 设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths +下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR` -比如SDK文件夹(默认为lib)与工程文件在同一级目录下,则都设置为"$(SRCROOT)/[文件夹名称]"即可。 -4. 确认一下的框架是存在的(Target -> Build Phases -> Link Binary With Libraries) +1. 用xcode打开iOS工程 将`$JPUSH_PLUGIN_DIR`/src/ios/Plugins/拖到project中 +2. 将`$JPUSH_PLUGIN_DIR`/src/ios/lib/拖到project中 + +4. 添加以下框架,打开xocode,点击project,选择(Target -> Build Phases -> Link Binary With Libraries) CFNetwork.framework CoreFoundation.framework @@ -21,42 +21,32 @@ 并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数 +10. 在AppDelegate.m中包含头文件 + + #import "APService.h" + #import "JPushPlugin.h" 6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能 - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - { - #if __has_feature(objc_arc) - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - #else - self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; - #endif - self.window.backgroundColor = [UIColor whiteColor]; - [self.window makeKeyAndVisible]; - - // Required - [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | - UIRemoteNotificationTypeSound | - UIRemoteNotificationTypeAlert)]; - // Required - [APService setupWithOption:launchOptions]; - + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ + //原内容保持不变 + //Required add + [JPushPlugin setLaunchOptions:launchOptions]; return YES; } - - - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - - // Required + - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + //原内容保持不变 + // Required add [APService registerDeviceToken:deviceToken]; } - - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - + //原内容保持不变 // Required [APService handleRemoteNotification:userInfo]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification + object:userInfo]; } - 7. 修改phonegap config.xml文件用来包含Plugin/内的插件 @@ -66,7 +56,7 @@ -8. 复制www/PushNotification.js到工程的www目录下面 +8. 复制`$JPUSH_PLUGIN_DIR`/www/PushNotification.js到工程的www目录下面 9. 在需要使用插件处加入