mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 22:42:51 +08:00
fix Cordova CLI auto install in document
This commit is contained in:
parent
40828ff145
commit
f0c6374409
93
README.md
93
README.md
@ -1,5 +1,8 @@
|
|||||||
## JPush PhoneGap Plugin ##
|
## JPush PhoneGap Plugin ##
|
||||||
###创建项目###
|
|
||||||
|
|
||||||
|
###准备工作
|
||||||
|
|
||||||
1. cordova create 文件夹名字 包名 应用名字
|
1. cordova create 文件夹名字 包名 应用名字
|
||||||
|
|
||||||
cordova create Myproj com.myproj.jpush MyTestProj
|
cordova create Myproj com.myproj.jpush MyTestProj
|
||||||
@ -13,67 +16,62 @@
|
|||||||
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
||||||
然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加
|
然后再执行`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
|
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)
|
||||||
|
|
||||||
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||||
|
|
||||||
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 $JPUSH_PLUGIN_DIR
|
||||||
cordova plugin add org.apache.cordova.device
|
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();
|
+ 在AppDelegate.m文件中,添加JPush SDK 提供的 API 来实现功能
|
||||||
window.plugins.jPushPlugin.setDebugMode(true);
|
|
||||||
|
|
||||||
|
- (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自动安装
|
window.plugins.jPushPlugin.init();
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
### Android 手工安装
|
### Android 手工安装
|
||||||
|
|
||||||
@ -94,6 +92,7 @@
|
|||||||
src/ios/example/js/* to www/js
|
src/ios/example/js/* to www/js
|
||||||
|
|
||||||
###关于'phonegap build'云服务
|
###关于'phonegap build'云服务
|
||||||
|
|
||||||
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
||||||
|
|
||||||
###常见错误
|
###常见错误
|
||||||
@ -133,7 +132,6 @@
|
|||||||
event - jpush.openNotification
|
event - jpush.openNotification
|
||||||
|
|
||||||
+ 获取自定义消息推送内容
|
+ 获取自定义消息推送内容
|
||||||
|
|
||||||
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
||||||
+ 页面的统计
|
+ 页面的统计
|
||||||
|
|
||||||
@ -177,7 +175,6 @@
|
|||||||
+ 统计分析 API
|
+ 统计分析 API
|
||||||
|
|
||||||
onResume / onPause(java api)
|
onResume / onPause(java api)
|
||||||
|
|
||||||
|
|
||||||
+ 清除通知 API
|
+ 清除通知 API
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#Android 手工安装
|
#Android 手工安装
|
||||||
|
|
||||||
1. 复制src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||||
2. 复制src/android/armeabi/libjpush.so 到lib/armeabi/
|
|
||||||
3. 复制src/android/jpush-sdk-release1.5.0.jar 到lib/
|
1. 复制:`$JPUSH_PLUGIN_DIR`/src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
||||||
4. 复制src/android/test_notification_layout.xml到res/layout/
|
2. 复制:`$JPUSH_PLUGIN_DIR`/src/android/armeabi/libjpush.so 到lib/armeabi/
|
||||||
5. 复制src/android/jpush_notification_icon.png 到res/drawable/
|
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 节点下添加以下权限
|
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||||
|
|
||||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
### IOS手工安装
|
### IOS手工安装
|
||||||
|
|
||||||
1. 添加src/ios/Plugins/到project中
|
下载jpush phonegap插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||||
2. 添加src/ios/lib/到project中
|
|
||||||
3. 设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths
|
|
||||||
|
|
||||||
比如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
|
CFNetwork.framework
|
||||||
CoreFoundation.framework
|
CoreFoundation.framework
|
||||||
@ -21,42 +21,32 @@
|
|||||||
|
|
||||||
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
|
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
|
||||||
|
|
||||||
|
10. 在AppDelegate.m中包含头文件
|
||||||
|
|
||||||
|
#import "APService.h"
|
||||||
|
#import "JPushPlugin.h"
|
||||||
|
|
||||||
6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||||
{
|
//原内容保持不变
|
||||||
#if __has_feature(objc_arc)
|
//Required add
|
||||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
[JPushPlugin setLaunchOptions:launchOptions];
|
||||||
#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];
|
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
//原内容保持不变
|
||||||
|
// Required add
|
||||||
// Required
|
|
||||||
[APService registerDeviceToken:deviceToken];
|
[APService registerDeviceToken:deviceToken];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||||
|
//原内容保持不变
|
||||||
// Required
|
// Required
|
||||||
[APService handleRemoteNotification:userInfo];
|
[APService handleRemoteNotification:userInfo];
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||||
|
object:userInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
7. 修改phonegap config.xml文件用来包含Plugin/内的插件
|
7. 修改phonegap config.xml文件用来包含Plugin/内的插件
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +56,7 @@
|
|||||||
</feature>
|
</feature>
|
||||||
|
|
||||||
|
|
||||||
8. 复制www/PushNotification.js到工程的www目录下面
|
8. 复制`$JPUSH_PLUGIN_DIR`/www/PushNotification.js到工程的www目录下面
|
||||||
9. 在需要使用插件处加入
|
9. 在需要使用插件处加入
|
||||||
|
|
||||||
<script type="text/javascript" src="JPushPlugin.js"></script>
|
<script type="text/javascript" src="JPushPlugin.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user