Compare commits

...

18 Commits

Author SHA1 Message Date
zhangqinghe 4215437bd6 document add abaut phoengap cloud build 2014-07-25 10:06:06 +08:00
zhangqinghe 8db89c9f2e fix document in appkey 2014-07-24 19:09:29 +08:00
zhangqinghe 992246235d delete callback not used 2014-07-24 16:41:42 +08:00
zhangqinghe 8e0fee7276 fix last commit error 2014-07-24 14:52:14 +08:00
zhangqinghe 734077536b add new JPushPlugin ,else plugin not loaded 2014-07-23 17:08:13 +08:00
zhangqinghe bce9508ec5 find back receive message form android 2014-07-23 14:46:02 +08:00
zhangqinghe ea685713db delete openNotificationForIos 2014-07-23 14:39:47 +08:00
zhangqinghe 4c810fcaa9 change verion to v1.5.4 2014-07-23 09:52:18 +08:00
zhangqinghe 213e5b7bb1 spelling mistakes 2014-07-22 20:14:01 +08:00
zhangqinghe 1af99fe4bf add message in app 2014-07-22 18:51:48 +08:00
zhangqinghe 3e55f6f2c4 fix android open notification and message callback in js 2014-07-17 09:51:45 +08:00
zhangqinghe ec40fd3e58 delete more log 2014-07-16 15:24:59 +08:00
zhangqinghe e6819f54e2 fix log 2014-07-10 18:09:06 +08:00
zhangqinghe 386d1282e9 delete space in document 2014-07-10 15:51:06 +08:00
zhangqinghe d55a46c54c fix document 2014-07-10 15:46:30 +08:00
zhangqinghe bfe0a76ae0 fix a part Android Doc form READ.me 2014-07-10 15:03:30 +08:00
zhangqinghe 7cc3239e1b fix push notificaiton and add open notificaiotn evet 2014-07-10 14:57:03 +08:00
qinghe.zhang 34857a1eea Update README.md 2014-06-27 10:05:27 +08:00
7 changed files with 338 additions and 264 deletions
+35 -40
View File
@@ -1,43 +1,46 @@
## JPush PhoneGap Plugin ##
###创建项目###
1. cordova create 文件夹名字 包名 应用名字
```
cordova create Myproj com.myproj.jpush MyTestProj
```
2. 添加平台
```
cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded]
cordova platform add android
```
### Android自动安装 ###
### Android使用PhoneGap/Cordova CLI自动安装
1. 使用 phonegap 或者 cordova cli 添加插件(建议在git客户端下使用,在windows 的cmd界面下 该命令提示git command line tool 不可用):
```
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
```
2. 修改www/config.xml文件,添加或者覆盖以下字段
####IOS使用PhoneGap/Cordova CLI自动安装
2. 修改[your project]/plugins/android.json生成脚本的JPUSH_APPKEY字段
"xml": "<meta-data android:name=\"JPUSH_APPKEY\" android:value=\"your appkey in JPush Portal\" />",
3. 执行 cordova build android 使修改的`JPUSH_APPKEY`写入AndroidManifest.xml文件
> 温馨提示:如果使用eclipse来生成安装包,步骤2与步骤3可省略。直接在AndroidManifest.xml文件中修改JPUSH_APPKEY即可
###IOS使用PhoneGap/Cordova CLI自动安装
1. 使用PhoneGap/Cordova CLI命令安装
```
cordova plugin add https://github.com/zhangqinghe/test.phonegap.git
cordova platforms add ios
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
cordova build ios
```
2. 修改Resources/PushConfig.plist文件
```
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
```
3.添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
3. 添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
@@ -57,8 +60,6 @@ cordova build ios
// Required
[APService handleRemoteNotification:userInfo];
}
```
###Android 手工安装###
1. 复制src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
@@ -68,7 +69,6 @@ cordova build ios
5. 复制src/android/jpush_notification_icon.png 到res/drawable/
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
```
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
@@ -84,10 +84,9 @@ cordova build ios
<permission
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
```
7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
```
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
@@ -168,19 +167,16 @@ cordova build ios
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
```
### IOS手工安装
1. 添加src/ios/Plugins/到project中
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)
```
CFNetwork.framework
CoreFoundation.framework
@@ -189,16 +185,14 @@ SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
```
5. 在你的工程中创建一个新的Property List文件
```
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
```
6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
@@ -227,29 +221,30 @@ UIKit.framework
// Required
[APService handleRemoteNotification:userInfo];
}
```
7. 修改phonegap config.xml文件用来包含Plugin/内的插件
```
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" />
<param name="onload" value="true" />
</feature>
```
8. 复制www/PushNotification.js到工程的www目录下面
9. 在需要使用插件处加入
```
<script type="text/javascript" src="JPushPlugin.js"></script>
```
###示例
1. 完整的示例可以点击网页右侧的"Download Zip"下载,下载完成后在文件的"src/ios/example"文件夹内找到并拷贝以下文件
```
src/ios/example/index.html to www/index.html
src/ios/example/css/* to www/css
src/ios/example/js/* to www/js
```
###关于'phonegap build'云服务
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
+3 -9
View File
@@ -11,7 +11,7 @@
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
var onDeviceReady = function(){
console.log("Device ready!")
console.log("JPushPlugin:Device ready!")
initiateUI();
}
var onTagsWithAlias = function(event){
@@ -28,7 +28,7 @@
}
var onGetRegistradionID = function(data) {
try{
console.log("index.registrationID:"+data)
console.log("JPushPlugin:registrationID is "+data)
$("#registrationid").html(data);
}
@@ -40,7 +40,6 @@
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
//test android interface
//window.plugins.jPushPlugin.getNotification(onNotification);
//window.plugins.jPushPlugin.stopPush()
//window.plugins.jPushPlugin.resumePush();
//window.plugins.jPushPlugin.clearAllNoticication();
@@ -48,7 +47,7 @@
//window.plugins.jPushPlugin.stopPush();
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
//window.plugins.jPushPlugin.init();
//window.plugins.jPushPlugin.setDebugable(true);
//window.plugins.jPushPlugin.setDebugMode(true);
//window.plugins.jPushPlugin.startLogPageView("mianPage");
$("#setTagWithAliasButton").click(function(ev) {
@@ -87,11 +86,6 @@
<body>
<div data-role="page" id="page">
<div data-role="header" class="ui-bar ui-bar-b">
<center>
<img border="0" src="img/logo.png" alt="Urban Airship" align="center" />
</center>
</div>
<div data-role="content">
<form>
<div class="ui-body ui-body-b">
+1 -1
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cn.jpush.phonegap.JPushPlugin"
version="1.5.3">
version="1.5.4">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
+44 -22
View File
@@ -37,7 +37,7 @@ public class JPushPlugin extends CordovaPlugin {
"setCustomPushNotificationBuilder",
"setPushTime",
"init",
"setDebugable",
"setDebugMode",
"stopPush",
"resumePush",
"isPushStopped",
@@ -74,13 +74,24 @@ public class JPushPlugin extends CordovaPlugin {
return data;
}
private static JSONObject openNotificationObject(String alert,
Map<String, String> extras){
JSONObject data = new JSONObject();
try {
data.put("alert", alert);
data.put("extras", new JSONObject(extras));
} catch (JSONException e) {
}
return data;
}
static void transmitPush(String message, Map<String, String> extras) {
if (instance == null) {
return;
}
JSONObject data = notificationObject(message, extras);
String js = String
.format("window.plugins.jPushPlugin.pushCallback(%s);",
.format("window.plugins.jPushPlugin.recieveMessageInAndroidCallback(%s);",
data.toString());
try {
instance.webView.sendJavascript(js);
@@ -90,7 +101,22 @@ public class JPushPlugin extends CordovaPlugin {
}
}
static void transmitOpen(String alert, Map<String, String> extras) {
if (instance == null) {
return;
}
JSONObject data = openNotificationObject(alert, extras);
String js = String
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);",
data.toString());
try {
instance.webView.sendJavascript(js);
} catch (NullPointerException e) {
} catch (Exception e) {
}
}
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {
@@ -114,10 +140,10 @@ public class JPushPlugin extends CordovaPlugin {
void init(JSONArray data,CallbackContext callbackContext){
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
callbackContext.success();
//callbackContext.success();
}
void setDebugable(JSONArray data, CallbackContext callbackContext) {
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
String mode;
try {
mode = data.getString(0);
@@ -147,8 +173,8 @@ public class JPushPlugin extends CordovaPlugin {
void isPushStopped(JSONArray data,
CallbackContext callbackContext){
boolean isStoped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
if(isStoped){
boolean isStopped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
if(isStopped){
callbackContext.success(1);
}else{
callbackContext.success(0);
@@ -174,13 +200,13 @@ public class JPushPlugin extends CordovaPlugin {
void setPushTime(JSONArray data,
CallbackContext callbackContext){
Set<Integer> days = new HashSet<Integer>();
JSONArray dayArr;
JSONArray dayArray;
int startHour = -1;
int endHour = -1;
try {
dayArr = data.getJSONArray(0);
for (int i = 0; i < dayArr.length(); i++) {
days.add(dayArr.getInt(i));
dayArray = data.getJSONArray(0);
for (int i = 0; i < dayArray.length(); i++) {
days.add(dayArray.getInt(i));
}
} catch (JSONException e) {
e.printStackTrace();
@@ -212,8 +238,8 @@ public class JPushPlugin extends CordovaPlugin {
tags= new HashSet<String>();
}else{
tagStr = data.getString(0);
String[] tagArr = tagStr.split(",");
for (String tag : tagArr) {
String[] tagArray = tagStr.split(",");
for (String tag : tagArray) {
tags.add(tag);
}
}
@@ -244,9 +270,9 @@ public class JPushPlugin extends CordovaPlugin {
String alias;
try {
alias = data.getString(0);
JSONArray tagsArr = data.getJSONArray(1);
for (int i = 0; i < tagsArr.length(); i++) {
tags.add(tagsArr.getString(i));
JSONArray tagsArray = data.getJSONArray(1);
for (int i = 0; i < tagsArray.length(); i++) {
tags.add(tagsArray.getString(i));
}
JPushInterface.setAliasAndTags(this.cordova.getActivity()
@@ -288,7 +314,7 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) {
e.printStackTrace();
}
callbackContext.success(obj);
//callbackContext.success(obj);
}
void setCustomPushNotificationBuilder(JSONArray data,
@@ -305,13 +331,13 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) {
e.printStackTrace();
}
callbackContext.success(obj);
//callbackContext.success(obj);
}
void clearAllNotification(JSONArray data,
CallbackContext callbackContext){
JPushInterface.clearAllNotifications(this.cordova.getActivity());
callbackContext.success();
//callbackContext.success();
}
void clearNotificationById(JSONArray data,
@@ -348,10 +374,6 @@ public class JPushPlugin extends CordovaPlugin {
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
data.toString());
instance.webView.sendJavascript(jsEvent);
String js = String
.format("window.plugins.jPushPlugin.pushCallback('%s');",
data.toString());
instance.webView.sendJavascript(js);
} catch (JSONException e) {
+2
View File
@@ -50,6 +50,8 @@ public class MyReceiver extends BroadcastReceiver {
JPushPlugin.notificationAlert = alert;
JPushPlugin.notificationExtras = extras;
JPushPlugin.transmitOpen(alert, extras);
context.startActivity(launch);
}
private Map<String, String> getNotificationExtras(Intent intent) {
+35 -4
View File
@@ -11,11 +11,24 @@
@implementation JPushPlugin
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
if (self=[super initWithWebView:theWebView]) {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kAPNetworkDidReceiveMessageNotification
object:nil];
}
return self;
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) {
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
return ;
}
NSString *alias=[arguments objectAtIndex:0];
@@ -51,8 +64,8 @@
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registratonID = [APService registrionID];
CDVPluginResult *result=[self pluginResultForValue:registratonID];
NSString* registrationID = [APService registrionID];
CDVPluginResult *result=[self pluginResultForValue:registrationID];
if (result) {
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
} else {
@@ -78,7 +91,7 @@
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
});
}
@@ -141,5 +154,23 @@
return result;
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
NSLog(@"%@",userInfo);
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@",jsonString);
dispatch_async(dispatch_get_main_queue(), ^{
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
});
}
@end
+46 -16
View File
@@ -1,3 +1,4 @@
var JPushPlugin = function(){
};
@@ -76,14 +77,50 @@ JPushPlugin.prototype.setAlias = function(data){
}
}
JPushPlugin.prototype.pushCallback = function(data){
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
try{
console.log("JPushPlugin:receiveMessageIniOSCallback--data:"+data);
var bToObj = JSON.parse(data);
var content = bToObj.content;
console.log(content);
}
catch(exception){
console.log("JPushPlugin:receiveMessageIniOSCallback"+exception);
}
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
try{
console.log("JPushPlugin:pushCallback--data:"+data);
var bToObj=JSON.parse(data);
var message = bToObj.message;
var extras = bToObj.extras;
console.log(message);
console.log(extras['cn.jpush.android.MSG_ID']);
console.log(extras['cn.jpush.android.CONTENT_TYPE']);
console.log(extras['cn.jpush.android.EXTRA']);
}
catch(exception){
console.log("JPushPlugin:pushCallback "+exception);
}
}
//
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
try{
console.log(data);
var bToObj = JSON.parse(data);
var code = bToObj.resultCode;
var tags = bToObj.resultTags;
var alias = bToObj.resultAlias;
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
var alert = bToObj.alert;
var extras = bToObj.extras;
console.log(alert);
console.log(extras['cn.jpush.android.MSG_ID']);
console.log(extras['app']);
console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
console.log(extras['cn.jpush.android.EXTRA']);
console.log(extras['cn.jpush.android.PUSH_ID']);
console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
console.log("JPushPlugin:openNotificationCallback is ready");
}
catch(exception){
console.log(exception);
@@ -91,13 +128,6 @@ JPushPlugin.prototype.pushCallback = function(data){
}
//android single
JPushPlugin.prototype.getNotification = function (callback) {
if(device.platform == "Android") {
data=[];
this.call_native("getNotification",data,callback);
}
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
if(device.platform == "Android") {
data=[]
@@ -126,7 +156,7 @@ JPushPlugin.prototype.resumePush = function(){
}
}
JPushPlugin.prototype.clearAllNoticication = function(){
JPushPlugin.prototype.clearAllNotification = function(){
if(device.platform == "Android") {
data=[]
this.call_native("clearAllNotification",data,null);
@@ -153,13 +183,13 @@ JPushPlugin.prototype.init = function(){
}
}
JPushPlugin.prototype.setDebugable = function(mode){
JPushPlugin.prototype.setDebugMode = function(mode){
if(device.platform == "Android") {
this.call_native("setDebugable",[mode],null);
this.call_native("setDebugMode",[mode],null);
}
}
//ios single
//iOS single
if(!window.plugins){