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
+77 -82
View File
@@ -1,43 +1,46 @@
## 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
```
2. 添加平台 2. 添加平台
```
cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded]
cordova platform add android
```
### Android自动安装 ### cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded]
cordova platform add android
### Android使用PhoneGap/Cordova CLI自动安装
1. 使用 phonegap 或者 cordova cli 添加插件(建议在git客户端下使用,在windows 的cmd界面下 该命令提示git command line tool 不可用): 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文件,添加或者覆盖以下字段 cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
####IOS使用PhoneGap/Cordova CLI自动安装
1.使用PhoneGap/Cordova CLI命令安装 2. 修改[your project]/plugins/android.json生成脚本的JPUSH_APPKEY字段
```
cordova plugin add https://github.com/zhangqinghe/test.phonegap.git "xml": "<meta-data android:name=\"JPUSH_APPKEY\" android:value=\"your appkey in JPush Portal\" />",
cordova platforms add ios
cordova build ios 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/jpush/jpush-phonegap-plugin.git
cordova build ios
2. 修改Resources/PushConfig.plist文件
2.修改Resources/PushConfig.plist文件
```
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle 在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
```
3.添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 3. 添加监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
{
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
@@ -48,17 +51,15 @@ cordova build ios
// Required // Required
[APService setupWithOption:launchOptions]; [APService setupWithOption:launchOptions];
return YES; return YES;
} }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Required // 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];
} }
```
###Android 手工安装### ###Android 手工安装###
1. 复制src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下) 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/ 5. 复制src/android/jpush_notification_icon.png 到res/drawable/
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限 6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
```
<!-- Required 一些系统要求的权限,如访问网络等--> <!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/> <uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/> <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
@@ -84,10 +84,9 @@ cordova build ios
<permission <permission
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/> android:protectionLevel="signature"/>
```
7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明 7. 修改AndroidManifest.xml 在 manifest/application 节点下添加SDK相关组件声明
```
<activity <activity
android:name="cn.jpush.android.ui.PushActivity" android:name="cn.jpush.android.ui.PushActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" android:theme="@android:style/Theme.Translucent.NoTitleBar"
@@ -168,40 +167,35 @@ cordova build ios
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/> <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/> <meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
```
### IOS手工安装 ### IOS手工安装
1.添加src/ios/Plugins/到project中 1. 添加src/ios/Plugins/到project中
2.添加src/ios/lib/到project中 2. 添加src/ios/lib/到project中
3.设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths 3. 设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths
```
比如SDK文件夹(默认为lib)与工程文件在同一级目录下,则都设置为"$(SRCROOT)/[文件夹名称]"即可。 比如SDK文件夹(默认为lib)与工程文件在同一级目录下,则都设置为"$(SRCROOT)/[文件夹名称]"即可。
```
4.确认一下的框架是存在的(Target -> Build Phases -> Link Binary With Libraries) 4. 确认一下的框架是存在的(Target -> Build Phases -> Link Binary With Libraries)
```
CFNetwork.framework CFNetwork.framework
CoreFoundation.framework CoreFoundation.framework
CoreTelephony.framework CoreTelephony.framework
SystemConfiguration.framework SystemConfiguration.framework
CoreGraphics.framework CoreGraphics.framework
Foundation.framework Foundation.framework
UIKit.framework UIKit.framework
```
5.在你的工程中创建一个新的Property List文件
```
并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数 5. 在你的工程中创建一个新的Property List文件
```
6.调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能 并将其命名为PushConfig.plist,填入Portal为你的应用提供的APP_KEY等参数
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 6. 调用代码,监听系统事件,相应地调用 JPush SDK 提供的 API 来实现功能
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
@@ -214,42 +208,43 @@ UIKit.framework
[APService setupWithOption:launchOptions]; [APService setupWithOption:launchOptions];
return YES; return YES;
} }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Required // 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];
} }
```
7.修改phonegap config.xml文件用来包含Plugin/内的插件
```
<feature name="JPushPlugin"> 7. 修改phonegap config.xml文件用来包含Plugin/内的插件
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" /> <param name="ios-package" value="JPushPlugin" />
<param name="onload" value="true" /> <param name="onload" value="true" />
</feature> </feature>
```
8.复制www/PushNotification.js到工程的www目录下面
9.在需要使用插件处加入
```
<script type="text/javascript" src="JPushPlugin.js"></script> 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 1. 完整的示例可以点击网页右侧的"Download Zip"下载,下载完成后在文件的"src/ios/example"文件夹内找到并拷贝以下文件
src/ios/example/css/* to www/css
src/ios/example/js/* to www/js
```
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" src="cordova.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var onDeviceReady = function(){ var onDeviceReady = function(){
console.log("Device ready!") console.log("JPushPlugin:Device ready!")
initiateUI(); initiateUI();
} }
var onTagsWithAlias = function(event){ var onTagsWithAlias = function(event){
@@ -28,7 +28,7 @@
} }
var onGetRegistradionID = function(data) { var onGetRegistradionID = function(data) {
try{ try{
console.log("index.registrationID:"+data) console.log("JPushPlugin:registrationID is "+data)
$("#registrationid").html(data); $("#registrationid").html(data);
} }
@@ -40,7 +40,6 @@
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID); window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
//test android interface //test android interface
//window.plugins.jPushPlugin.getNotification(onNotification);
//window.plugins.jPushPlugin.stopPush() //window.plugins.jPushPlugin.stopPush()
//window.plugins.jPushPlugin.resumePush(); //window.plugins.jPushPlugin.resumePush();
//window.plugins.jPushPlugin.clearAllNoticication(); //window.plugins.jPushPlugin.clearAllNoticication();
@@ -48,7 +47,7 @@
//window.plugins.jPushPlugin.stopPush(); //window.plugins.jPushPlugin.stopPush();
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped); //window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
//window.plugins.jPushPlugin.init(); //window.plugins.jPushPlugin.init();
//window.plugins.jPushPlugin.setDebugable(true); //window.plugins.jPushPlugin.setDebugMode(true);
//window.plugins.jPushPlugin.startLogPageView("mianPage"); //window.plugins.jPushPlugin.startLogPageView("mianPage");
$("#setTagWithAliasButton").click(function(ev) { $("#setTagWithAliasButton").click(function(ev) {
@@ -87,11 +86,6 @@
<body> <body>
<div data-role="page" id="page"> <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"> <div data-role="content">
<form> <form>
<div class="ui-body ui-body-b"> <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" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="cn.jpush.phonegap.JPushPlugin" id="cn.jpush.phonegap.JPushPlugin"
version="1.5.3"> version="1.5.4">
<name>JPush Plugin</name> <name>JPush Plugin</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
+44 -22
View File
@@ -37,7 +37,7 @@ public class JPushPlugin extends CordovaPlugin {
"setCustomPushNotificationBuilder", "setCustomPushNotificationBuilder",
"setPushTime", "setPushTime",
"init", "init",
"setDebugable", "setDebugMode",
"stopPush", "stopPush",
"resumePush", "resumePush",
"isPushStopped", "isPushStopped",
@@ -74,13 +74,24 @@ public class JPushPlugin extends CordovaPlugin {
return data; 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) { static void transmitPush(String message, Map<String, String> extras) {
if (instance == null) { if (instance == null) {
return; return;
} }
JSONObject data = notificationObject(message, extras); JSONObject data = notificationObject(message, extras);
String js = String String js = String
.format("window.plugins.jPushPlugin.pushCallback(%s);", .format("window.plugins.jPushPlugin.recieveMessageInAndroidCallback(%s);",
data.toString()); data.toString());
try { try {
instance.webView.sendJavascript(js); 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 @Override
public boolean execute(final String action, final JSONArray data, public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException { final CallbackContext callbackContext) throws JSONException {
@@ -114,10 +140,10 @@ public class JPushPlugin extends CordovaPlugin {
void init(JSONArray data,CallbackContext callbackContext){ void init(JSONArray data,CallbackContext callbackContext){
JPushInterface.init(this.cordova.getActivity().getApplicationContext()); JPushInterface.init(this.cordova.getActivity().getApplicationContext());
callbackContext.success(); //callbackContext.success();
} }
void setDebugable(JSONArray data, CallbackContext callbackContext) { void setDebugMode(JSONArray data, CallbackContext callbackContext) {
String mode; String mode;
try { try {
mode = data.getString(0); mode = data.getString(0);
@@ -147,8 +173,8 @@ public class JPushPlugin extends CordovaPlugin {
void isPushStopped(JSONArray data, void isPushStopped(JSONArray data,
CallbackContext callbackContext){ CallbackContext callbackContext){
boolean isStoped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext()); boolean isStopped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
if(isStoped){ if(isStopped){
callbackContext.success(1); callbackContext.success(1);
}else{ }else{
callbackContext.success(0); callbackContext.success(0);
@@ -174,13 +200,13 @@ public class JPushPlugin extends CordovaPlugin {
void setPushTime(JSONArray data, void setPushTime(JSONArray data,
CallbackContext callbackContext){ CallbackContext callbackContext){
Set<Integer> days = new HashSet<Integer>(); Set<Integer> days = new HashSet<Integer>();
JSONArray dayArr; JSONArray dayArray;
int startHour = -1; int startHour = -1;
int endHour = -1; int endHour = -1;
try { try {
dayArr = data.getJSONArray(0); dayArray = data.getJSONArray(0);
for (int i = 0; i < dayArr.length(); i++) { for (int i = 0; i < dayArray.length(); i++) {
days.add(dayArr.getInt(i)); days.add(dayArray.getInt(i));
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@@ -212,8 +238,8 @@ public class JPushPlugin extends CordovaPlugin {
tags= new HashSet<String>(); tags= new HashSet<String>();
}else{ }else{
tagStr = data.getString(0); tagStr = data.getString(0);
String[] tagArr = tagStr.split(","); String[] tagArray = tagStr.split(",");
for (String tag : tagArr) { for (String tag : tagArray) {
tags.add(tag); tags.add(tag);
} }
} }
@@ -244,9 +270,9 @@ public class JPushPlugin extends CordovaPlugin {
String alias; String alias;
try { try {
alias = data.getString(0); alias = data.getString(0);
JSONArray tagsArr = data.getJSONArray(1); JSONArray tagsArray = data.getJSONArray(1);
for (int i = 0; i < tagsArr.length(); i++) { for (int i = 0; i < tagsArray.length(); i++) {
tags.add(tagsArr.getString(i)); tags.add(tagsArray.getString(i));
} }
JPushInterface.setAliasAndTags(this.cordova.getActivity() JPushInterface.setAliasAndTags(this.cordova.getActivity()
@@ -288,7 +314,7 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
callbackContext.success(obj); //callbackContext.success(obj);
} }
void setCustomPushNotificationBuilder(JSONArray data, void setCustomPushNotificationBuilder(JSONArray data,
@@ -305,13 +331,13 @@ public class JPushPlugin extends CordovaPlugin {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
callbackContext.success(obj); //callbackContext.success(obj);
} }
void clearAllNotification(JSONArray data, void clearAllNotification(JSONArray data,
CallbackContext callbackContext){ CallbackContext callbackContext){
JPushInterface.clearAllNotifications(this.cordova.getActivity()); JPushInterface.clearAllNotifications(this.cordova.getActivity());
callbackContext.success(); //callbackContext.success();
} }
void clearNotificationById(JSONArray data, void clearNotificationById(JSONArray data,
@@ -348,10 +374,6 @@ public class JPushPlugin extends CordovaPlugin {
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)", .format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
data.toString()); data.toString());
instance.webView.sendJavascript(jsEvent); instance.webView.sendJavascript(jsEvent);
String js = String
.format("window.plugins.jPushPlugin.pushCallback('%s');",
data.toString());
instance.webView.sendJavascript(js);
} catch (JSONException e) { } catch (JSONException e) {
+2
View File
@@ -50,6 +50,8 @@ public class MyReceiver extends BroadcastReceiver {
JPushPlugin.notificationAlert = alert; JPushPlugin.notificationAlert = alert;
JPushPlugin.notificationExtras = extras; JPushPlugin.notificationExtras = extras;
JPushPlugin.transmitOpen(alert, extras);
context.startActivity(launch); context.startActivity(launch);
} }
private Map<String, String> getNotificationExtras(Intent intent) { private Map<String, String> getNotificationExtras(Intent intent) {
+35 -4
View File
@@ -11,11 +11,24 @@
@implementation JPushPlugin @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{ -(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments; NSArray *arguments=command.arguments;
if (!arguments||[arguments count]<2) { if (!arguments||[arguments count]<2) {
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]]; // [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
return ; return ;
} }
NSString *alias=[arguments objectAtIndex:0]; NSString *alias=[arguments objectAtIndex:0];
@@ -51,8 +64,8 @@
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{ -(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registratonID = [APService registrionID]; NSString* registrationID = [APService registrionID];
CDVPluginResult *result=[self pluginResultForValue:registratonID]; CDVPluginResult *result=[self pluginResultForValue:registrationID];
if (result) { if (result) {
[self succeedWithPluginResult:result withCallbackID:command.callbackId]; [self succeedWithPluginResult:result withCallbackID:command.callbackId];
} else { } else {
@@ -78,7 +91,7 @@
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]]; [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; 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 @end
+47 -17
View File
@@ -1,3 +1,4 @@
var JPushPlugin = function(){ 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{ try{
console.log(data); console.log(data);
var bToObj=JSON.parse(data); var bToObj = JSON.parse(data);
var code = bToObj.resultCode; var alert = bToObj.alert;
var tags = bToObj.resultTags; var extras = bToObj.extras;
var alias = bToObj.resultAlias; console.log(alert);
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
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){ catch(exception){
console.log(exception); console.log(exception);
@@ -91,13 +128,6 @@ JPushPlugin.prototype.pushCallback = function(data){
} }
//android single //android single
JPushPlugin.prototype.getNotification = function (callback) {
if(device.platform == "Android") {
data=[];
this.call_native("getNotification",data,callback);
}
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){ JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
if(device.platform == "Android") { if(device.platform == "Android") {
data=[] data=[]
@@ -126,7 +156,7 @@ JPushPlugin.prototype.resumePush = function(){
} }
} }
JPushPlugin.prototype.clearAllNoticication = function(){ JPushPlugin.prototype.clearAllNotification = function(){
if(device.platform == "Android") { if(device.platform == "Android") {
data=[] data=[]
this.call_native("clearAllNotification",data,null); 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") { if(device.platform == "Android") {
this.call_native("setDebugable",[mode],null); this.call_native("setDebugMode",[mode],null);
} }
} }
//ios single //iOS single
if(!window.plugins){ if(!window.plugins){