Compare commits

...

90 Commits

Author SHA1 Message Date
darkterrorooo
0af2f60dbb Merge pull request #98 from darkterrorooo/master
fix doc
2015-12-01 16:18:04 +08:00
darkterrorooo
0da9f0ed26 fix doc 2015-12-01 16:15:58 +08:00
darkterrorooo
f3bc83d97b fix doc 2015-12-01 16:14:52 +08:00
darkterrorooo
8b674bb777 fix doc 2015-12-01 16:13:51 +08:00
darkterrorooo
181ab80dab Merge pull request #97 from darkterrorooo/master
修正文档,在添加插件时填写 APP KEY
2015-12-01 16:11:45 +08:00
darkterrorooo
de59d7919b fix doc 2015-12-01 16:06:41 +08:00
darkterrorooo
1102ad3a57 fix doc 2015-12-01 16:05:37 +08:00
darkterrorooo
a8e4060b4d fix doc 2015-12-01 16:03:08 +08:00
darkterrorooo
3b234f3101 修复抽离了APP KEY后的文档 2015-12-01 15:40:16 +08:00
darkterrorooo
7c580b4eaf 修复抽离了APP KEY后的文档 2015-12-01 15:30:41 +08:00
darkterrorooo
af267eda94 修复抽离了APP KEY后的文档 2015-12-01 15:28:39 +08:00
darkterrorooo
d93b35611b 修复抽离了APP KEY后的文档 2015-12-01 15:27:45 +08:00
darkterrorooo
d94ccfb8d8 修复抽离了APP KEY后的文档 2015-12-01 15:24:31 +08:00
darkterrorooo
b24b7064ba 修复抽离了APP KEY后的文档 2015-12-01 15:18:40 +08:00
darkterrorooo
f12e7a35d0 Merge pull request #65 from wgjtyu/master
抽离API_KEY的配置
2015-12-01 12:15:55 +08:00
darkterrorooo
37c1d308eb Merge pull request #96 from darkterrorooo/master
升级iOS, Android到最新的SDK
2015-11-26 15:38:08 +08:00
darkterrorooo
c2818fb193 修正iOS 接口 isPushStopped 的返回值,使stop 返回 1,非stop 返回 0 2015-11-26 13:10:58 +08:00
darkterrorooo
32d3ecc917 升级iOS SDK, 升级到 1.8.8
升级 Android SDK, 升级到 2.0.5

	modified:   plugin.xml
	modified:   src/android/MyReceiver.java
2015-11-26 12:07:38 +08:00
George
138fde1587 Merge remote-tracking branch 'jpush/master' into test 2015-09-10 20:13:45 +08:00
zhangqinghe
f54252dd4f 修复文档中关于iOS appkey的部分 2015-08-18 13:51:26 +08:00
zhangqinghe
96c27448a0 Merge branch 'master' of https://github.com/jpush/jpush-phonegap-plugin 2015-08-10 17:20:26 +08:00
zhangqinghe
2211e68e68 fix #67 2015-08-10 17:19:56 +08:00
zhangqinghe
6a74a1697b fix #66 2015-08-10 17:00:16 +08:00
George
3196aeff72 Android端清除指定消息 2015-08-06 17:51:03 +08:00
George
ca2e52fe54 抽离API_KEY的配置 2015-08-06 11:08:28 +08:00
zhangqinghe
a2c311730d fix #62 about document 2015-08-05 14:45:44 +08:00
zhangqinghe
f624670b4f fix #62 2015-08-03 13:34:36 +08:00
zhangqinghe
5ade8c3300 fix #57 2015-07-21 17:44:29 +08:00
zhangqinghe
c2f957acbe 修复程序彻底退出后,点击通知收不到消息的bug 2015-07-21 12:48:51 +08:00
zhangqinghe
b10bc7dbb4 Merge branch 'dev' of https://github.com/jpush/jpush-phonegap-plugin into dev 2015-07-17 15:25:25 +08:00
zhangqinghe
126e54d5b1 fix #53 2015-07-17 15:21:39 +08:00
zhangqinghe
7984b8acf0 fix fir android sdk 1.7.5 plugin.xml 2015-07-10 17:45:19 +08:00
zhangqinghe
1fbc14b677 change iOS sdk from v1.8.2 to 1.8.3 2015-07-10 17:45:19 +08:00
zhangqinghe
5fdd31b960 change android sdk form 1.7.3 to 1.7.5 2015-07-10 17:45:18 +08:00
zhangqinghe
b3e404ef12 修正JPushPlugin.prototype.receiveMessageInAndroidCallback的bug 2015-07-10 17:45:18 +08:00
zhangqinghe
1082fbd8c4 修改关于jpush.receiveNotification的文档,并删除旧有说明 2015-07-10 17:45:18 +08:00
zhangqinghe
c420ae20e5 add jpush.receiveNotificaiton event in platform android 2015-07-10 17:45:18 +08:00
zhangqinghe
c826b0d94a fix fir android sdk 1.7.5 plugin.xml 2015-07-10 17:44:03 +08:00
zhangqinghe
79d0b5e037 change iOS sdk from v1.8.2 to 1.8.3 2015-07-10 17:44:03 +08:00
zhangqinghe
5836cac41f change android sdk form 1.7.3 to 1.7.5 2015-07-10 17:44:02 +08:00
zhangqinghe
8ea95cd5ef fix #47 2015-07-10 17:44:02 +08:00
zhangqinghe
c90c9b7b01 fix #47 2015-07-03 16:39:25 +08:00
zhangqinghe
ef339a1b96 修正JPushPlugin.prototype.receiveMessageInAndroidCallback的bug 2015-06-10 15:58:37 +08:00
zhangqinghe
0233a10906 修改关于jpush.receiveNotification的文档,并删除旧有说明 2015-06-09 17:31:57 +08:00
zhangqinghe
cb8f8412b4 add jpush.receiveNotificaiton event in platform android 2015-06-09 16:38:46 +08:00
zhangqinghe
4e2b2d6bb6 fix document about ios in content-avalible 2015-04-24 14:49:20 +08:00
zhangqinghe
8b3aa0b90e fix /strios/example to example 2015-04-16 14:56:06 +08:00
zhangqinghe
2e5cfdaa5a fix document about example position 2015-04-16 14:15:11 +08:00
zhangqinghe
7fcefce3ce fix android message and notification event 2015-04-15 16:59:32 +08:00
zhangqinghe
ce8ca9f8f8 fix when app not launch tap notification,and not receice jpush.openNotification 2015-04-14 16:15:25 +08:00
zhangqinghe
93fbc893ca ducument add event jpush.receiveMessage 2015-04-14 15:11:21 +08:00
zhangqinghe
7545a948bd demo add openNotification receiveNotification receiveMessage code 2015-04-14 14:47:57 +08:00
zhangqinghe
2510289d95 about lazy load mode explanation 2015-04-14 13:35:29 +08:00
zhangqinghe
41c5c04dc1 move android api position 2015-04-14 13:08:41 +08:00
zhangqinghe
82dd47eefa move andorid init api to common api document 2015-04-14 11:35:27 +08:00
zhangqinghe
f0c6374409 fix Cordova CLI auto install in document 2015-04-14 11:21:09 +08:00
zhangqinghe
40828ff145 move jpush sdk inital method to JPushPlugin static method 2015-04-14 10:05:14 +08:00
zhangqinghe
cbca41a513 Adjustment documents structure 2015-04-14 09:58:44 +08:00
zhangqinghe
fbd98732c8 fix dicument about open notification event when app is launching 2015-04-10 13:45:15 +08:00
zhangqinghe
ff86dc1230 add open notification evnet when app is launching 2015-04-10 13:42:25 +08:00
zhangqinghe
2dbd0cb248 add 'jpush.openNotificaiton'event in iOS ducoment 2015-04-10 11:11:26 +08:00
zhangqinghe
a049e2e62d add open notificaiton event when app run background 2015-04-10 11:04:56 +08:00
zhangqinghe
bf003c84c1 add registrationID in document 2015-03-30 11:13:52 +08:00
zhangqinghe
ced9ad3a1e fix abot api isPushStoped and resumePush in document 2015-03-30 11:02:33 +08:00
zhangqinghe
27378f6ca0 add new iterface 'isPushStopped' and 'resumePush' for platform iOS 2015-03-30 10:28:01 +08:00
zhangqinghe
58b8cd45b2 增加设置本地的badge值的api 2015-03-25 16:11:04 +08:00
qinghe.zhang
6d668101c5 Merge pull request #32 from yaonie084/master
fix README.md for use cordovar 4.x
2015-03-19 15:29:27 +08:00
ethan
67ca37d55a fix README.md for cordovar 4.x 2015-03-19 14:41:19 +08:00
zhangqinghe
e78d5bd544 fix jpush.receiveNotification in document 2015-03-19 13:37:48 +08:00
zhangqinghe
d92723301e delete OnPuase in Document 2015-03-18 17:07:38 +08:00
zhangqinghe
605fcf4a62 remove deprecated interface writeJavascript 2015-03-18 15:34:16 +08:00
zhangqinghe
e66336f670 update android sdk version to v1.7.3 2015-03-17 14:18:12 +08:00
zhangqinghe
2797bdd0e7 add ducoment about with JPushPlugin.h 2015-03-10 17:38:14 +08:00
zhangqinghe
a197975d03 upadte js event 'jpush.receiveNotification' 2015-03-10 16:58:09 +08:00
zhangqinghe
27c4fe7b26 add event jpush.receiveNotification in object-c file 2015-03-10 16:46:44 +08:00
zhangqinghe
aae9e8314a add js event jpush.receiveNotification 2015-03-10 16:37:08 +08:00
zhangqinghe
7d489c7f20 Merge branch 'dev' of ssh://github.com/jpush/jpush-phonegap-plugin into dev 2015-02-14 16:26:05 +08:00
zhangqinghe
c3cfa01e60 delete openNotificaiton error simple 2015-02-14 16:24:09 +08:00
zhangqinghe
27ebdd6809 增加了打开通知的event回调 2015-02-14 16:24:09 +08:00
qinghe.zhang
e945bcf53d Merge pull request #29 from Samurais/master
#28 stream cn.jpush.android.EXTRA from JSONObject to String
2015-02-14 16:23:01 +08:00
Samurais
cc858c2464 #28 stream cn.jpush.android.EXTRA from JSONObject to String 2015-02-14 16:07:31 +08:00
zhangqinghe
1b93f5e026 delete openNotificaiton error simple 2015-01-27 18:31:05 +08:00
zhangqinghe
46e0c1879c 增加了打开通知的event回调 2015-01-27 18:19:16 +08:00
zhangqinghe
fe7c52f2c9 add open notificaiton event interface's document 2015-01-27 15:40:46 +08:00
zhangqinghe
f217eda463 添加统计代码 2015-01-26 14:40:44 +08:00
zhangqinghe
95fc690dd3 fix ducoment's error 2015-01-26 14:30:28 +08:00
zhangqinghe
260c298f6b 增加统计接口 2015-01-26 14:23:45 +08:00
zhangqinghe
7c1c29a7ec add interface init and setDebugMode in example 2015-01-19 17:48:41 +08:00
qinghe.zhang
0aed054039 Merge pull request #22 from Samurais/master
#21 fix json parse issue in openNotificationInAndroidCallback
2015-01-19 17:07:01 +08:00
Samurais
95194695fe #21 fix json parse issue in openNotificationInAndroidCallback 2014-12-15 17:07:55 +08:00
27 changed files with 1566 additions and 773 deletions

838
README.md
View File

@@ -1,279 +1,73 @@
## JPush PhoneGap Plugin ##
###创建项目###
l## JPush PhoneGap Plugin ##
###准备工作
1. cordova create 文件夹名字 包名 应用名字
cordova create Myproj com.myproj.jpush MyTestProj
2. 添加平台
cd Myproj :不进入项目会出现[RangeError:Maximum call stack size exceeded]
cd Myproj
cordova platform add android
cordova platform add ios
### Android使用PhoneGap/Cordova CLI自动安装
1. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
ps:这里请注意iOS平台必须先执行 `cordova platform add ios`,
然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加
git clone https://github.com/jpush/jpush-phonegap-plugin.git
2.`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如9fed5bcb7b9b87413678c407
<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)
###Cordova CLI/Phonegap 安装 Android & iOS
1). 安装JPush PhoneGap Plugin。 有两种方法。
方法一: 在线安装
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
方法二:下载到本地再安装
使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
4. cordova cli 添加jpush phonegap插件和依赖的device插件:
cordova plugin add $JPUSH_PLUGIN_DIR
cordova plugin add org.apache.cordova.device
git clone https://github.com/jpush/jpush-phonegap-plugin.git
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
5. 在js中调用函数,初始化jpush sdk
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.setDebugMode(true);
2). 安装org.apache.cordova.device
cordova plugin add org.apache.cordova.device
###IOS使用PhoneGap/Cordova CLI自动安装
3). 在js中调用函数,初始化jpush sdk
1. 使用PhoneGap/Cordova CLI命令安装
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 来实现功能
window.plugins.jPushPlugin.init();
//由于phonegap插件采用了Lazy load的特性 所以这里建议在js文件能执行的最开始就加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Required
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
   if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
    //可以添加自定义categories
    [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                   UIUserNotificationTypeSound |
                                                   UIUserNotificationTypeAlert)
                                       categories:nil];
  } else {
    //categories 必须为nil
    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                   UIRemoteNotificationTypeSound |
                                                   UIRemoteNotificationTypeAlert)
                                       categories:nil];
  }
#else
    //categories 必须为nil
  [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                 UIRemoteNotificationTypeSound |
                                                 UIRemoteNotificationTypeAlert)
                                     categories:nil];
#endif
    // Required
    [APService setupWithOption:launchOptions];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Required
[APService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required
[APService handleRemoteNotification:userInfo];
}
###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/
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<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"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
</activity>
<!-- Required SDK核心功能-->
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
</service>
<!-- Required SDK 核心功能-->
<service
android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER"/>
<action android:name="cn.jpush.android.intent.REPORT"/>
<action android:name="cn.jpush.android.intent.PushService"/>
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
</intent-filter>
</service>
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
<!--Required 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
<!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="cn.jpush.phonegap.MyReceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
<!-- Required 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
<!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
<!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
<!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
<!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
</receiver>
<!-- Required SDK核心功能-->
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
### Android 手工安装
[Android 手工安装文档地址](document/Android_handle_install.md)
### IOS手工安装
1. 添加src/ios/Plugins/到project中
2. 添加src/ios/lib/到project中
3. 设置 Search Paths 下的 User Header Search Paths 和 Library Search Paths
[IOS手工安装文档地址](document/iOS_handle_install.md)
比如SDK文件夹默认为lib与工程文件在同一级目录下则都设置为"$(SRCROOT)/[文件夹名称]"即可。
4. 确认一下的框架是存在的(Target -> Build Phases -> Link Binary With Libraries)
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
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
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// Required
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
// Required
[APService setupWithOption:launchOptions];
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Required
[APService registerDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// 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"文件夹内找到并拷贝以下文件
1. "$JPUSH_PLUGIN_DIR/example"文件夹内找到并拷贝以下文件
src/ios/example/index.html to www/index.html
src/ios/example/css/* to www/css
src/ios/example/js/* to www/js
src/example/index.html to www/index.html
src/example/css/* to www/css
src/example/js/* to www/js
###关于'phonegap build'云服务
该项目基于cordova实现目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
###常见错误
1. androd
@@ -287,470 +81,112 @@
* android:[YOUR__ANDROID_PROJECT]/assets/www/plugins/cn.jpush.phonegap.JPushPlugin/www
* iOS:[YOUR_iOS_PROJEcT]/www/plugins/cn.jpush.phonegap.JPushPlugin/www
这里只说明public的函数
具体的API请参考这里
#### iOS和adnroid通用API简介
+ 停止与恢复推送服务 API
window.plugins.jPushPlugin.init()
window.plugins.jPushPlugin.stopPush()
window.plugins.jPushPlugin.resumePush()
window.plugins.jPushPlugin.isPushStopped(callback)
#### API - setTagsWithAlias,setTags,setAlias
+ 获取 RegistrationID API
提供几个相关 API 用来设置别名alias与标签tags
这几个 API 可以在 App 里任何地方调用。
别名 alias
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
每个用户只能指定一个别名。
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户当给指定这个别名发消息时服务器端API会同时给这多个用户发送消息。
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端API发通知到客户端提醒用户。
标签 tag
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
可为每个用户打多个标签。
不同应用程序、不同的用户,可以打同样的标签。
举例: game, old_page, women
##### 接口定义
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias)
JPushPlugin.prototype.setTags = function(tags)
JPushPlugin.prototype.setAlias = function(alias)
#####使用平台
android iOS
##### 参数说明
* tags
* 参数类型为数组
* nil 此次调用不设置此值
* 空集合表示取消之前的设置
* 每次调用至少设置一个 tag覆盖之前的设置不是新增
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag但总长度不得超过1K字节。判断长度需采用UTF-8编码
* 单个设备最多支持设置 100 个 tag。App 全局 tag 数量无限制。
* alias
* 参数类型为字符串
* nil 此次调用不设置此值
* 空字符串 "")表示取消之前的设置
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
* 限制alias 命名长度限制为 40 字节。判断长度需采用UTF-8编码
window.plugins.jPushPlugin.getRegistrationID(callback)
+ 别名与标签 API
##### 返回值说明
window.plugins.jPushPlugin.setTagsWithAlias(tags,alias)
window.plugins.jPushPlugin.setTags(tags)
window.plugins.jPushPlugin.setAlias(alias)
+ 获取点击通知内容
event - jpush.openNotification
+ 获取通知内容
event - jpush.receiveNotification
函数本身无返回值,但需要注册`jpush.setTagsWithAlias `事件来监听设置结果
+ 获取自定义消息推送内容
event - jpush.receiveMessage
[通用API详细说明](document/Common_detail_api.md)
#### iOS API简介
+ 获取自定义消息推送内容
event - jpush.receiveMessage
//推荐使用事件的方式传递但同时保留了receiveMessageIniOSCallback的回调函数兼容以前的代码
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
+ 页面的统计
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
var onTagsWithAlias = function(event){
try{
console.log("onTagsWithAlias");
var result="result code:"+event.resultCode+" ";
result+="tags:"+event.tags+" ";
result+="alias:"+event.alias+" ";
$("#tagAliasResult").html(result);
}
catch(exception){
console.log(exception)
}
}
window.plugins.jPushPlugin.startLogPageView (pageName)
window.plugins.jPushPlugin.stopLogPageView (pageName)
window.plugins.jPushPlugin.beginLogPageView (pageName,duration)
+ 设置Badge
#####错误码定义
window.plugins.jPushPlugin.setBadge(value)
window.plugins.jPushPlugin.resetBadge()
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
+ 本地通知
|Code|描述|详细解释|
|-|-|-|
|6001| 无效的设置tag/alias 不应参数都为 null||
|6002| 设置超时| 建议重试|
|6003| alias| 字符串不合法 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|6004| alias超长。最多 40个字节 中文 UTF-8 是 3 个字节|
|6005| 某一个 tag 字符串不合法| 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|6006| 某一个 tag 超长。|一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节|
|6007| tags 数量超出限制。最多 100个| 这是一台设备的限制。一个应用全局的标签数量无限制。|
|6008| tag/alias 超出总长度限制。|总长度最多 1K 字节|
|6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁|
#### API - startLogPageView,stopLogPageView,beginLogPageView
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确才能够获取正确的页面访问路径、访问深度PV的数据。
##### 接口定义
JPushPlugin.prototype.startLogPageView = function(pageName)
JPushPlugin.prototype.stopLogPageView = function(pageName)
JPushPlugin.prototype.beginLogPageView = function(pageName,duration)
#####平台
iOS
#####参数说明
pageName 需要统计页面自定义名称
duration 自定义的页面时间
#####调用说明
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
#####返回值说明
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
window.plugins.jPushPlugin.startLogPageView("onePage");
window.plugins.jPushPlugin.stopLogPageView("onePage");
}
+ 后续版本加入
+ 日志等级设置
#### API - setBadge,resetBadge
badge是iOS用来标记应用程序状态的一个数字出现在程序图标右上角。 JPush封装badge功能允许应用上传badge值至JPush服务器由JPush后台帮助管理每个用户所对应的推送badge值简化了设置推送badge的操作。
实际应用中开发者可以直接对badge值做增减操作无需自己维护用户与badge值之间的对应关系。
##### 接口定义
JPushPlugin.prototype.setBadge = function(value)
JPushPlugin.prototype.resetBadge = function()
`resetBadge相当于setBadge(0)`
##### 平台
iOS
##### 参数说明
value 取值范围:[0,99999]
##### 返回值
控制台会有log打印设置结果
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setBadge(5);
window.plugins.jPushPlugin.reSetBadge();
}
#### API - setDebugModeFromIos
API 用于开启Debug模式显示更多的日志信息
建议调试时开启这个选项不调试的时候注释这句代码这个函数setLogOFF是相反的一对
##### 接口定义
JPushPlugin.prototype.setDebugModeFromIos = function()
##### 平台
iOS
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setDebugModeFromIos();
}
#### API - setLogOFF
API用来关闭日志信息除了必要的错误信息
不需要任何调试信息的时候调用此API 发布时建议调用此API用来屏蔽日志信息节省性能消耗)
##### 平台
iOS
##### 接口定义
JPushPlugin.prototype.setLogOFF = function()
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setLogOFF();
}
#### API - receiveMessageIniOSCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 使用平台
iOS
##### 参数说明
- data 是一个js字符串使用如下代码解析js具体key根据应用内消息来确定
var bToObj = JSON.parse(data);
#### API - init
调用此API,用来
JPush SDK 提供的推送服务是默认开启的。
##### 接口定义
JPushPlugin.prototype.init = function()
##### 参数说明
##### 返回值
#### API - setDebugMode
用于开启调试模式可以查看集成JPush过程中的log如果集成失败可方便定位问题所在
##### 接口定义
JPushPlugin.prototype.setDebugMode = function(mode)
##### 参数说明
- num 保存的条数
##### 返回值
#### API - stopPush
开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时则必须要调用恢复推送服务 API。
调用了本 API 后JPush 推送服务完全被停止。具体表现为:
JPush Service 不在后台运行
收不到推送消息
不能通过 JPushInterface.init 恢复需要调用resumePush恢复
极光推送所有的其他 API 调用都无效
##### 接口定义
JPushPlugin.prototype.stopPush = function()
#####平台
android
##### 参数说明
##### 返回值
#### API - resumePush
恢复推送服务。
调用了此 API 后,极光推送完全恢复正常工作。
##### 接口定义
JPushPlugin.prototype.resumePush = function()
##### 参数说明
##### 返回值
#### API - isPushStopped
用来检查 Push Service 是否已经被停止
##### 接口定义
JPushPlugin.prototype.isPushStopped = function(callback)
#####平台
android
##### 参数说明
+ callback 回调函数用来通知JPush的推送服务是否开启
var onCallback = function(data) {
if(data>0){
//开启
}else{
//关闭
}
}
##### 返回值
#### API - setBasicPushNotificationBuilder,setCustomPushNotificationBuilder
当用户需要定制默认的通知栏样式时,则可调用此方法。
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
- setBasicPushNotificationBuilder
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
- setCustomPushNotificationBuilder
- 继承 Basic 进一步让开发者定制 Notification Layout
如果不调用此方法定制则极光Push SDK 默认的通知栏样式是Android标准的通知栏提示。
#####平台
android
##### 接口定义
JPushPlugin.prototype.setBasicPushNotificationBuilder = function()
JPushPlugin.prototype.setCustomPushNotificationBuilder = function()
#### 参数说明
##### 返回值
#### API - clearAllNotification
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
##### 接口定义
JPushPlugin.prototype.clearAllNotification = function()
#####平台
android
##### 参数说明
##### 返回值
#### API - setLatestNotificationNum
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
新版本 SDK (v1.3.0) 增加此功能,限制保留的通知条数。默认为保留最近 5 条通知。
开发者可通过调用此 API 来定义为不同的数量。
##### 接口定义
JPushPlugin.prototype.setLatestNotificationNum = function(num)
#####平台
android
##### 参数说明
- num 保存的条数
##### 返回值
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
本地通知API不依赖于网络无网条件下依旧可以触发
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知
#####接口定义
JPushPlugin.prototype.addLocalNotification = function(builderId,
content,
title,
notificaitonID,
broadcastTime,
extras)
JPushPlugin.prototype.removeLocalNotification = function(notificationID)
JPushPlugin.prototype.clearLocalNotifications = function()
#####平台
android
##### 参数说明
- builderId 设置本地通知样式
- content 设置本地通知的content
- title 设置本地通知的title
- notificaitonID 设置本地通知的ID
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
- extras 设置额外的数据信息extras为json字符串
##### 返回值说明
#### API - receiveMessageInAndroidCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 接口定义
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data)
#####平台
android
##### 参数说明
- data 接收到的js字符串
##### 返回值
#### API - receiveMessageInAndroidCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 接口定义
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data)
#####平台
android
##### 参数说明
- data 接收到的js字符串包含的key:value请进入该函数体查看
##### 返回值
window.plugins.jPushPlugin.setDebugModeFromIos ()
window.plugins.jPushPlugin.setLogOFF()
[iOS API详细说明](document/iOS_detail_api.md)
#### adnroid API简介
+ 获取集成日志
window.plugins.jPushPlugin.setDebugMode(mode)
+ 接收推送消息和点击通知
//下面这两个api 是兼容旧有的代码
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
+ 统计分析 API
onResume / onPause(java api)
+ 清除通知 API
window.plugins.jPushPlugin.clearAllNotification()
+ 通知栏样式定制 API
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
+ 设置保留最近通知条数 API
window.plugins.jPushPlugin.setLatestNotificationNum(num)
+ 本地通知API
window.plugins.jPushPlugin.addLocalNotification(builderId,
content,
title,
notificaitonID,
broadcastTime,
extras)
window.plugins.jPushPlugin.removeLocalNotification(notificationID)
window.plugins.jPushPlugin.clearLocalNotifications()
[Android API详细说明](document/Android_detail_api.md)
###更多
[JPush官网文档](http://docs.jpush.io/)

View File

@@ -0,0 +1,185 @@
## adnroid API简介
### 获取集成日志
#### API - setDebugMode
用于开启调试模式可以查看集成JPush过程中的log如果集成失败可方便定位问题所在
##### 接口定义
window.plugins.jPushPlugin.setDebugMode (mode)
##### 参数说明
- mode的值
- true 显示集成日志
- false 不显示集成日志
### 接收消息和点击通知事件
#### API - receiveMessageInAndroidCallback
用于android收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
##### 接口定义
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
##### 参数说明
- data 接收到的js字符串包含的key:value请进入该函数体查看
##### 代码示例
#### API - openNotificationInAndroidCallback
当点击android手机的通知栏进入应用程序时,会调用这个函数,这个函数不需要主动调用,是作为回调函数来用的
##### 接口定义
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
##### 参数说明
- data js字符串
##### 代码示例
### 统计分析 API
#### API - onResume / onPause
这是一个 android local api不是js的api请注意
本 API 用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器,在 Portal 上展示给开发者。
####接口定义
public static void onResume(final Activity activity)
public static void onPause(final Activity activity)
####参数说明
Activity activity 当前所在的Activity。
####调用说明
应在所有的 Activity 的 onResume / onPause 方法里调用。
####代码示例
@Override
protected void onResume() {
super.onResume();
JPushInterface.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
JPushInterface.onPause(this);
}
#### API - reportNotificationOpened
用于上报用户的通知栏被打开,或者用于上报用户自定义消息被展示等客户端需要统计的事件。
##### 接口定义
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
##### 参数说明
- msgID
-收到的通知或者自定义消息的id
### 清除通知 API
#### API - clearAllNotification
推送通知到客户端时,由 JPush SDK 展现通知到通知栏上。
此 API 提供清除通知的功能,包括:清除所有 JPush 展现的通知(不包括非 JPush SDK 展现的)
##### 接口定义
window.plugins.jPushPlugin.clearAllNotification = function()
### 设置允许推送时间 API
### 设置通知静默时间 API
### 通知栏样式定制 API
#### API - setBasicPushNotificationBuilder,setCustomPushNotificationBuilder
当用户需要定制默认的通知栏样式时,则可调用此方法。
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
- setBasicPushNotificationBuilder
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
- setCustomPushNotificationBuilder
- 继承 Basic 进一步让开发者定制 Notification Layout
如果不调用此方法定制则极光Push SDK 默认的通知栏样式是Android标准的通知栏提示。
##### 接口定义
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
### 设置保留最近通知条数 API
#### API - setLatestNotificationNum
通过极光推送,推送了很多通知到客户端时,如果用户不去处理,就会有很多保留在那里。
新版本 SDK (v1.3.0) 增加此功能,限制保留的通知条数。默认为保留最近 5 条通知。
开发者可通过调用此 API 来定义为不同的数量。
##### 接口定义
window.plugins.jPushPlugin.setLatestNotificationNum(num)
##### 参数说明
- num 保存的条数
### 本地通知API
#### API - addLocalNotification,removeLocalNotification,clearLocalNotifications
本地通知API不依赖于网络无网条件下依旧可以触发
本地通知与网络推送的通知是相互独立的,不受保留最近通知条数上限的限制
本地通知的定时时间是自发送时算起的,不受中间关机等操作的影响
三个接口的功能分别为:添加一个本地通知,删除一个本地通知,删除所有的本地通知
#####接口定义
window.plugins.jPushPlugin.addLocalNotification = function(builderId,
content,
title,
notificaitonID,
broadcastTime,
extras)
window.plugins.jPushPlugin.removeLocalNotification = function(notificationID)
window.plugins.jPushPlugin.clearLocalNotifications = function()
##### 参数说明
- builderId 设置本地通知样式
- content 设置本地通知的content
- title 设置本地通知的title
- notificaitonID 设置本地通知的ID
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
- extras 设置额外的数据信息extras为json字符串

View File

@@ -0,0 +1,108 @@
#Android 手工安装
下载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 节点下添加以下权限
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<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"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
</activity>
<!-- Required SDK核心功能-->
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
</service>
<!-- Required SDK 核心功能-->
<service
android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER"/>
<action android:name="cn.jpush.android.intent.REPORT"/>
<action android:name="cn.jpush.android.intent.PushService"/>
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
</intent-filter>
</service>
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
<!--Required 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
<!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="cn.jpush.phonegap.MyReceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
<!-- Required 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
<!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
<!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
<!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
<!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
<category android:name="$PACKAGE_NAME"/>
</intent-filter>
</receiver>
<!-- Required SDK核心功能-->
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>

View File

@@ -0,0 +1,375 @@
#通用API说明
## 停止与恢复推送服务 API
### API - init
调用此API,用来开启
JPush SDK 提供的推送服务。
开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时则必须要调用恢复推送服务 API。
```
本功能是一个完全本地的状态操作。也就是说:停止推送服务的状态不会保存到服务器上。
如果停止推送服务后开发者App被重新安装或者被清除数据
JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
```
#### 接口定义
window.plugins.jPushPlugin.init()
### API - stopPush
+ 在android平台
+ 开发者App可以通过调用停止推送服务API来停止极光推送服务。当又需要使用极光推送服务时则必须要调用恢复推送服务 API。
+ 调用了本 API 后JPush 推送服务完全被停止。具体表现为:
+ JPush Service 不在后台运行
+ 收不到推送消息
+ 不能通过 JPushInterface.init 恢复需要调用resumePush恢复
+ 极光推送所有的其他 API 调用都无效
+ iOS平台
+ 不推荐调用因为这个API只是让你的DeviceToken失效在设置通知 中您的应用程序没有任何变化
+ 推荐设置一个UI界面 提醒用户在在设置-通知关闭推送服务
### 接口定义
window.plugins.jPushPlugin.stopPush()
#### API - resumePush
恢复推送服务。调用了此 API 后
+ 在android平台
+ 极光推送完全恢复正常工作,
+ iOS平台
+ 重新去APNS注册
##### 接口定义
window.plugins.jPushPlugin.resumePush()
#### API - isPushStopped
+ 在android平台
+ 用来检查 Push Service 是否已经被停止
+ iOS平台
+ 平台检查推送服务是否注册
##### 接口定义
window.plugins.jPushPlugin.isPushStopped(callback)
##### 参数说明
+ callback 回调函数用来通知JPush的推送服务是否开启
####代码示例
window.plugins.jPushPlugin.resumePush(callback)
var onCallback = function(data) {
if(data>0){
//开启
}else{
//关闭
}
}
##获取 RegistrationID API
### API - getRegistrationID
RegistrationID 定义
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
应用程序可以把此 RegistrationID 保存以自己的应用服务器上,然后就可以根据 RegistrationID 来向设备推送消息或者通知。
#### 接口定义
JPushPlugin.prototype.getRegistrationID = function(callback)
##### 参数说明
#### 返回值
调用此 API 来取得应用程序对应的 RegistrationID。 只有当应用程序成功注册到 JPush 的服务器时才返回对应的值,否则返回空字符串。
#### 调用示例
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
var onGetRegistradionID = function(data) {
try{
console.log("JPushPlugin:registrationID is "+data) }
catch(exception){
console.log(exception);
}
}
##别名与标签 API
### API - setTagsWithAlias,setTags,setAlias
提供几个相关 API 用来设置别名alias与标签tags
这几个 API 可以在 App 里任何地方调用。
别名 alias
为安装了应用程序的用户,取个别名来标识。以后给该用户 Push 消息时,就可以用此别名来指定。
每个用户只能指定一个别名。
同一个应用程序内,对不同的用户,建议取不同的别名。这样,尽可能根据别名来唯一确定用户。
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户当给指定这个别名发消息时服务器端API会同时给这多个用户发送消息。
举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端API发通知到客户端提醒用户。
标签 tag
为安装了应用程序的用户,打上标签。其目的主要是方便开发者根据标签,来批量下发 Push 消息。
可为每个用户打多个标签。
不同应用程序、不同的用户,可以打同样的标签。
举例: game, old_page, women
#### 接口定义
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias)
JPushPlugin.prototype.setTags = function(tags)
JPushPlugin.prototype.setAlias = function(alias)
####使用平台
android iOS
#### 参数说明
* tags
* 参数类型为数组
* nil 此次调用不设置此值
* 空集合表示取消之前的设置
* 每次调用至少设置一个 tag覆盖之前的设置不是新增
* 有效的标签组成:字母(区分大小写)、数字、下划线、汉字
* 限制:每个 tag 命名长度限制为 40 字节,最多支持设置 100 个 tag但总长度不得超过1K字节。判断长度需采用UTF-8编码
* 单个设备最多支持设置 100 个 tag。App 全局 tag 数量无限制。
* alias
* 参数类型为字符串
* nil 此次调用不设置此值
* 空字符串 "")表示取消之前的设置
* 有效的别名组成:字母(区分大小写)、数字、下划线、汉字。
* 限制alias 命名长度限制为 40 字节。判断长度需采用UTF-8编码
#### 返回值说明
函数本身无返回值,但需要注册`jpush.setTagsWithAlias `事件来监听设置结果
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
var onTagsWithAlias = function(event){
try{
console.log("onTagsWithAlias");
var result="result code:"+event.resultCode+" ";
result+="tags:"+event.tags+" ";
result+="alias:"+event.alias+" ";
$("#tagAliasResult").html(result);
}
catch(exception){
console.log(exception)
}
}
####错误码定义
|Code|描述|详细解释|
|-|-|-|
|6001| 无效的设置tag/alias 不应参数都为 null||
|6002| 设置超时| 建议重试|
|6003| alias| 字符串不合法 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|6004| alias超长。最多 40个字节 中文 UTF-8 是 3 个字节|
|6005| 某一个 tag 字符串不合法| 有效的别名、标签组成:字母(区分大小写)、数字、下划线、汉字。|
|6006| 某一个 tag 超长。|一个 tag 最多 40个字节 中文 UTF-8 是 3 个字节|
|6007| tags 数量超出限制。最多 100个| 这是一台设备的限制。一个应用全局的标签数量无限制。|
|6008| tag/alias 超出总长度限制。|总长度最多 1K 字节|
|6011| 10s内设置tag或alias大于3次| 短时间内操作过于频繁|
### 获取点击通知内容
#### event - jpush.openNotification
点击通知进入应用程序时会出发改事件
#####代码示例
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.openNotification", onOpenNotification, false);
- onOpenNotification需要这样写
var alertContent
if(device.platform == "Android"){
alertContent=window.plugins.jPushPlugin.openNotification.alert;
}else{
alertContent = event.aps.alert;
}
alert("open Notificaiton:"+alertContent);
ps点击通知后传递的json object 保存在window.plugins.jPushPlugin.openNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意
+ android
{"alert":"ding",
"extras":{
"cn.jpush.android.MSG_ID":"1691785879",
"app":"com.thi.pushtest",
"cn.jpush.android.ALERT":"ding",
"cn.jpush.android.EXTRA":{},
"cn.jpush.android.PUSH_ID":"1691785879",
"cn.jpush.android.NOTIFICATION_ID":1691785879,
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
+ iOS
{
"aps":{
"badge":1,
"sound":"default",
"alert":"今天去哪儿"
},
"_j_msgid":154604475
}
### 获取通知内容
#### event - jpush.receiveNotification
点击通知进入应用程序时会出发改事件
#####代码示例
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
- onReceiveNotification需要这样写
var alertContent
if(device.platform == "Android"){
alertContent=window.plugins.jPushPlugin.receiveNotification.alert;
}else{
alertContent = event.aps.alert;
}
alert("open Notificaiton:"+alertContent);
ps点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification直接访问即可字段示例根据实际推送情况可能略有差别请注意
+ android
{"alert":"ding",
"extras":{
"cn.jpush.android.MSG_ID":"1691785879",
"app":"com.thi.pushtest",
"cn.jpush.android.ALERT":"ding",
"cn.jpush.android.EXTRA":{},
"cn.jpush.android.PUSH_ID":"1691785879",
"cn.jpush.android.NOTIFICATION_ID":1691785879,
"cn.jpush.android.NOTIFICATION_TYPE":"0"}}
+ iOS
{
"aps":{
"badge":1,
"sound":"default",
"alert":"今天去哪儿"
},
"_j_msgid":154604475
}
### 获取自定义消息推送内容
####event - jpush.receiveMessage
收到应用内消息时触发这个事件
`推荐使用事件的方式传递但同时保留了receiveMessageIniOSCallback的回调函数兼容以前的代码`
#####代码示例
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
- onReceiveMessage需要这样写
var onReceiveMessage = function(event){
try{
var message
if(device.platform == "Android"){
message = window.plugins.jPushPlugin.receiveMessage.message;
}else{
message = event.content;
}
$("#messageResult").html(message);
}
catch(exception){
console.log("JPushPlugin:onReceiveMessage-->"+exception);
}
}
ps点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveMessage直接访问即可字段示例根据实际推送情况可能略有差别请注意
+ android
{"message":"今天去哪儿",
"extras"{
"cn.jpush.android.MSG_ID":"154378013",
"cn.jpush.android.CONTENT_TYPE":"",
"cn.jpush.android.EXTRA":{"key":"不添没有"}
}
}
+ iOS
{
"content":"今天去哪儿",
"extras":
{
"key":"不填写没有"
}
}

127
document/iOS_detail_api.md Normal file
View File

@@ -0,0 +1,127 @@
## iOS API简介
### 获取 APNs通知 推送内容
#### API - receiveMessageIniOSCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
不推荐使用回调函数
##### 接口定义
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data)
#####参数说明
- data 是一个js字符串使用如下代码解析js具体key根据应用内消息来确定
var bToObj = JSON.parse(data);
#####返回值
##### 代码示例
### 页面的统计
#### API - startLogPageView,stopLogPageView,beginLogPageView
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确才能够获取正确的页面访问路径、访问深度PV的数据。
##### 接口定义
window.plugins.jPushPlugin.startLogPageView = function(pageName)
window.plugins.jPushPlugin.stopLogPageView = function(pageName)
window.plugins.jPushPlugin.beginLogPageView = function(pageName,duration)
#####参数说明
pageName 需要统计页面自定义名称
duration 自定义的页面时间
#####调用说明
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
#####返回值说明
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
window.plugins.jPushPlugin.startLogPageView("onePage");
window.plugins.jPushPlugin.stopLogPageView("onePage");
}
### 设置Badge
#### API - setBadge,resetBadge
badge是iOS用来标记应用程序状态的一个数字出现在程序图标右上角。 JPush封装badge功能允许应用上传badge值至JPush服务器由JPush后台帮助管理每个用户所对应的推送badge值简化了设置推送badge的操作。
实际应用中开发者可以直接对badge值做增减操作无需自己维护用户与badge值之间的对应关系。
##### 接口定义
window.plugins.jPushPlugin.setBadge(value)
window.plugins.jPushPlugin.reSetBadge()
`resetBadge相当于setBadge(0)`
##### 参数说明
value 取值范围:[0,99999]
##### 返回值
控制台会有log打印设置结果
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setBadge(5);
window.plugins.jPushPlugin.reSetBadge();
}
#### API - setApplicationIconBadgeNumber
设置iOS的角标当设置badge0时为清除角标
##### 接口定义
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
##### 参数说明
- badge 整形,例如012
- 当badge为0时角标被清除
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
}
### 本地通知
### 日志等级设置
#### API - setDebugModeFromIos
API 用于开启Debug模式显示更多的日志信息
建议调试时开启这个选项不调试的时候注释这句代码这个函数setLogOFF是相反的一对
##### 接口定义
window.plugins.jPushPlugin.reSetBadge.setDebugModeFromIos()
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setDebugModeFromIos();
}
#### API - setLogOFF
API用来关闭日志信息除了必要的错误信息
不需要任何调试信息的时候调用此API 发布时建议调用此API用来屏蔽日志信息节省性能消耗)
##### 接口定义
window.plugins.jPushPlugin.reSetBadge.setLogOFF ()
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setLogOFF();
}

View File

@@ -0,0 +1,62 @@
### IOS手工安装
下载jpush phonegap插件并解压缩标记插件目录为`$JPUSH_PLUGIN_DIR`
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
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
5. 在你的工程中创建一个新的Property List文件
并将其命名为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{
//原内容保持不变
//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. 修改phonegap config.xml文件用来包含Plugin/内的插件
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" />
<param name="onload" value="true" />
</feature>
8. 复制`$JPUSH_PLUGIN_DIR`/www/PushNotification.js到工程的www目录下面
9. 在需要使用插件处加入
<script type="text/javascript" src="JPushPlugin.js"></script>

View File

@@ -13,7 +13,18 @@
var onDeviceReady = function(){
console.log("JPushPlugin:Device ready!")
initiateUI();
}
}
var onGetRegistradionID = function(data) {
try{
console.log("JPushPlugin:registrationID is "+data)
$("#registrationid").html(data);
}
catch(exception){
console.log(exception);
}
}
var onTagsWithAlias = function(event){
try{
console.log("onTagsWithAlias");
@@ -26,40 +37,71 @@
console.log(exception)
}
}
var onGetRegistradionID = function(data) {
var onOpenNotification = function(event){
try{
console.log("JPushPlugin:registrationID is "+data)
var alertContent
if(device.platform == "Android"){
alertContent=window.plugins.jPushPlugin.openNotification.alert;
}else{
alertContent = event.aps.alert;
}
alert("open Notificaiton:"+alertContent);
$("#registrationid").html(data);
}
catch(exception){
console.log(exception);
console.log("JPushPlugin:onOpenNotification"+exception);
}
}
var onReceiveNotification = function(event){
try{
var alert
if(device.platform == "Android"){
alert = window.plugins.jPushPlugin.receiveNotification.alert;
}else{
alert = event.aps.alert;
}
$("#notificationResult").html(alert);
}
catch(exeption){
console.log(exception)
}
}
var onReceiveMessage = function(event){
try{
var message
if(device.platform == "Android"){
message = window.plugins.jPushPlugin.receiveMessage.message;
}else{
message = event.content;
}
//var extras = window.plugins.jPushPlugin.extras
$("#messageResult").html(message);
}
catch(exception){
console.log("JPushPlugin:onReceiveMessage-->"+exception);
}
}
var initiateUI = function(){
try{
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
// var extras={"name":"json"};
// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras);
// window.plugins.jPushPlugin.removeLocalNotification(1111);
// window.plugins.jPushPlugin.clearLocalNotifications();
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
if(device.platform != "Android"){
window.plugins.jPushPlugin.setDebugModeFromIos();
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
}else{
window.plugins.jPushPlugin.setDebugMode(true);
}
}
catch(exception){
console.log(exception);
}
//test android interface
//window.plugins.jPushPlugin.stopPush()
//window.plugins.jPushPlugin.resumePush();
//window.plugins.jPushPlugin.clearAllNoticication();
//window.plugins.jPushPlugin.setLatestNotificationNum(5);
//window.plugins.jPushPlugin.stopPush();
//window.plugins.jPushPlugin.isPushStopped(onIsPushStopped);
//window.plugins.jPushPlugin.init();
//window.plugins.jPushPlugin.setDebugMode(true);
//window.plugins.jPushPlugin.startLogPageView("mianPage");
$("#setTagWithAliasButton").click(function(ev) {
try{
var tag1 = $("#tagText1").attr("value");
@@ -90,7 +132,13 @@
})
}
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
//jpush.receiveMessage
</script>
</head>
<body>
@@ -138,8 +186,19 @@
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
</div>
<div data-role="fieldcontain">
<label id="tagAliasPrompt" >设置tag/alias结果 </label>
<label id="tagAliasResult" >null</label>
</div>
<div data-role="fieldcontain">
<label id="notificationPrompt" >接受的通知内容:</label>
<label id="notificationResult" >null</label>
</div>
<div data-role="fieldcontain">
<label id="messagePrompt" >接受的自定义消息:</label>
<label id="messageResult" >null</label>
</div>
</div>
</form>
</div>

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="2.0.0">
version="2.0.2">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
@@ -10,12 +10,14 @@
<keywords>JPush,push</keywords>
<license>Apache 2.0 License</license>
<preference name="API_KEY" />
<engines>
<engine name="cordova" version=">=3.0"/>
</engines>
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="window.plugins.jPushPlugin"/>
<clobbers target="jPushPlugin"/>
</js-module>
<platform name="ios">
@@ -29,25 +31,31 @@
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
<header-file src="src/ios/lib/APService.h" />
<source-file src="src/ios/lib/libPushSDK.a" framework="true" />
<source-file src="src/ios/lib/libPushSDK-1.8.8.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h"/>
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
<resource-file src="src/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="CoreGraphics.framework" weak="true" />
<framework src="Foundation.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="UIKit.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="libz.dylib" weak="true" />
<config-file target="*PushConfig.plist" parent="APP_KEY">
<string>$API_KEY</string>
</config-file>
</platform>
<!-- android -->
<platform name="android">
<hook type="after_plugin_add" src="scripts/android-install.js" />
<hook type="after_plugin_install" src="scripts/android-install.js" />
<hook type="before_plugin_rm" src="scripts/android-install.js" />
<hook type="before_plugin_uninstall" src="scripts/android-install.js" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="JPushPlugin">
@@ -153,14 +161,16 @@
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
</config-file>
<source-file src="src/android/jpush-sdk-release1.7.2.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush172.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush172.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>
<source-file src="src/android/jpush-android-2.0.5.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush205.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush205.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/arm64-v8a/libjpush205.so" target-dir="libs/arm64-v8a"/>
<!--<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>-->
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
<source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable"/>
</platform>
</plugin>
</plugin>

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env node
module.exports = function (context) {
var path = context.requireCordovaModule('path'),
fs = context.requireCordovaModule('fs'),
shell = context.requireCordovaModule('shelljs'),
projectRoot = context.opts.projectRoot,
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")),
packageName = config.android_packageName() || config.packageName();
console.info("Running android-install.Hook: " + context.hook + ", Package: " + packageName + ", Path: " + projectRoot + ".");
if (!packageName) {
console.error("Package name could not be found!");
return ;
}
// android platform available?
if (context.opts.cordova.platforms.indexOf("android") === -1) {
console.info("Android platform has not been added.");
return ;
}
var targetDir = path.join(projectRoot, "platforms", "android", "src", "cn", "jpush", "phonegap");
targetFile = path.join(targetDir, "JPushPlugin.java");
console.log(targetDir);
if (['after_plugin_add', 'after_plugin_install', 'after_platform_add'].indexOf(context.hook) === -1) {
// remove it?
try {
fs.unlinkSync(targetFile);
} catch (err) {}
} else {
// create directory
shell.mkdir('-p', targetDir);
// sync the content
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'), {encoding: 'utf-8'}, function (err, data) {
if (err) {
throw err;
}
data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;');
fs.writeFileSync(targetFile, data);
});
}
};

View File

@@ -19,7 +19,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map.Entry;
import your.package.name.R;
import __PACKAGE_NAME__.R;
import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CustomPushNotificationBuilder;
@@ -46,15 +46,21 @@ public class JPushPlugin extends CordovaPlugin {
"setLatestNotificationNum",
"setPushTime",
"clearAllNotification",
"clearNotificationById",
"addLocalNotification",
"removeLocalNotification",
"clearLocalNotifications");
"clearLocalNotifications",
"onResume",
"onPause",
"reportNotificationOpened");
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static JPushPlugin instance;
public static String notificationAlert;
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
public static String openNotificationAlert;
public static Map<String, Object> openNotificationExtras=new HashMap<String, Object>();
public JPushPlugin() {
instance = this;
@@ -64,6 +70,16 @@ public class JPushPlugin extends CordovaPlugin {
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
//JPushInterface.setDebugMode(true);
//JPushPlugin.notificationAlert = alert;
//JPushPlugin.notificationExtras = extras;
if(JPushPlugin.openNotificationAlert != null){
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
}
if(JPushPlugin.notificationAlert!=null){
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
}
//JPushInterface.init(cordova.getActivity().getApplicationContext());
}
@@ -75,7 +91,12 @@ public class JPushPlugin extends CordovaPlugin {
data.put("message", message);
JSONObject jExtras = new JSONObject();
for(Entry<String,Object> entry:extras.entrySet()){
jExtras.put(entry.getKey(),entry.getValue());
if(entry.getKey().equals("cn.jpush.android.EXTRA")){
JSONObject jo = new JSONObject((String)entry.getValue());
jExtras.put("cn.jpush.android.EXTRA", jo);
} else {
jExtras.put(entry.getKey(),entry.getValue());
}
}
if(jExtras.length()>0)
{
@@ -94,7 +115,12 @@ public class JPushPlugin extends CordovaPlugin {
data.put("alert", alert);
JSONObject jExtras = new JSONObject();
for(Entry<String,Object> entry:extras.entrySet()){
jExtras.put(entry.getKey(),entry.getValue());
if(entry.getKey().equals("cn.jpush.android.EXTRA")){
JSONObject jo = new JSONObject((String)entry.getValue());
jExtras.put("cn.jpush.android.EXTRA", jo);
}else{
jExtras.put(entry.getKey(),entry.getValue());
}
}
if(jExtras.length()>0)
{
@@ -113,8 +139,15 @@ public class JPushPlugin extends CordovaPlugin {
String js = String
.format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback('%s');",
data.toString());
try {
instance.webView.sendJavascript(js);
// String jsEvent=String
// .format("cordova.fireDocumentEvent('jpush.receiveMessage',%s)",
// data.toString());
// instance.webView.sendJavascript(jsEvent);
} catch (NullPointerException e) {
} catch (Exception e) {
@@ -129,14 +162,56 @@ public class JPushPlugin extends CordovaPlugin {
String js = String
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
data.toString());
// {"alert":"ding",
// "extras":{
// "cn.jpush.android.MSG_ID":"1691785879",
// "app":"com.thi.pushtest",
// "cn.jpush.android.ALERT":"ding",
// "cn.jpush.android.EXTRA":{},
// "cn.jpush.android.PUSH_ID":"1691785879",
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
try {
instance.webView.sendJavascript(js);
// String jsEvent=String
// .format("cordova.fireDocumentEvent('jpush.openNotification',%s)",
// data.toString());
// instance.webView.sendJavascript(jsEvent);
} catch (NullPointerException e) {
} catch (Exception e) {
}
}
static void transmitReceive(String alert, Map<String, Object> extras) {
if (instance == null) {
return;
}
JSONObject data = openNotificationObject(alert, extras);
String js = String
.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
data.toString());
// {"alert":"ding",
// "extras":{
// "cn.jpush.android.MSG_ID":"1691785879",
// "app":"com.thi.pushtest",
// "cn.jpush.android.ALERT":"ding",
// "cn.jpush.android.EXTRA":{},
// "cn.jpush.android.PUSH_ID":"1691785879",
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
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 {
@@ -247,6 +322,23 @@ public class JPushPlugin extends CordovaPlugin {
String regID= JPushInterface.getRegistrationID(this.cordova.getActivity().getApplicationContext());
callbackContext.success(regID);
}
void onResume(JSONArray data, CallbackContext callbackContext) {
JPushInterface.onResume(this.cordova.getActivity());
}
void onPause(JSONArray data, CallbackContext callbackContext) {
JPushInterface.onPause(this.cordova.getActivity());
}
void reportNotificationOpened(JSONArray data, CallbackContext callbackContext) {
try {
String msgID;
msgID = data.getString(0);
JPushInterface.reportNotificationOpened(this.cordova.getActivity(),msgID);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void setTags(JSONArray data, CallbackContext callbackContext) {

View File

@@ -18,11 +18,12 @@ public class MyReceiver extends BroadcastReceiver {
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
}else if (JPushInterface.ACTION_UNREGISTER.equals(intent.getAction())){
// }else if (JPushInterface.ACTION_UNREGISTER.equals(intent.getAction())){
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
handlingReceivedMessage(intent);
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
handlingNotificationReceive(context,intent);
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
handlingNotificationOpen(context,intent);
@@ -37,6 +38,7 @@ public class MyReceiver extends BroadcastReceiver {
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
Map<String,Object> extras = getNotificationExtras(intent);
JPushPlugin.transmitPush(msg, extras);
}
private void handlingNotificationOpen(Context context,Intent intent){
@@ -47,13 +49,26 @@ public class MyReceiver extends BroadcastReceiver {
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
JPushPlugin.notificationAlert = alert;
JPushPlugin.notificationExtras = extras;
JPushPlugin.openNotificationAlert = alert;
JPushPlugin.openNotificationExtras = extras;
JPushPlugin.transmitOpen(alert, extras);
context.startActivity(launch);
}
private void handlingNotificationReceive(Context context,Intent intent){
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
Map<String,Object> extras = getNotificationExtras(intent);
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launch.addCategory(Intent.CATEGORY_LAUNCHER);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
JPushPlugin.notificationAlert = alert;
JPushPlugin.notificationExtras = extras;
JPushPlugin.transmitReceive(alert, extras);
}
private Map<String, Object> getNotificationExtras(Intent intent) {
Map<String, Object> extrasMap = new HashMap<String, Object>();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,15 @@
//
// AppDelegate+JPush.h
// delegateExtention
//
// Created by 张庆贺 on 15/8/3.
// Copyright (c) 2015年 JPush. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate (JPush)
//@property(nonatomic,strong)NSDictionary *luanchOption;
@end

View File

@@ -0,0 +1,74 @@
//
// AppDelegate+JPush.m
// delegateExtention
//
// Created by on 15/8/3.
// Copyright (c) 2015 JPush. All rights reserved.
//
#import "AppDelegate+JPush.h"
#import <objc/runtime.h>
#import "JPushPlugin.h"
#import "APService.h"
static char launchNotificationKey;
@implementation AppDelegate (JPush)
+(void)load{
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 {
[APService registerDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[APService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
object:userInfo];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
[APService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
object:userInfo];
}
//delegate
//-(NSDictionary *)luanchOption{
// return objc_getAssociatedObject(self, &launchNotificationKey);
//}
//-(void)setLuanchOption:(NSDictionary *)luanchOption{
// objc_setAssociatedObject(self, &launchNotificationKey, luanchOption, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//}
//-(void)dealloc{
// self.luanchOption=nil;
//}
@end

View File

@@ -8,10 +8,13 @@
#import <Cordova/CDV.h>
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
@interface JPushPlugin : CDVPlugin{
}
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions;
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;

View File

@@ -8,9 +8,26 @@
#import "JPushPlugin.h"
#import "APService.h"
#import <UIKit/UIKit.h>
static NSDictionary *_luanchOptions=nil;
@implementation JPushPlugin
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_luanchOptions=theLaunchOptions;
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
[APService setupWithOption:_luanchOptions];
}
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
}
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
if (self=[super initWithWebView:theWebView]) {
@@ -19,7 +36,30 @@
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginReceiveNotification
object:nil];
if (_luanchOptions) {
NSDictionary *userInfo = [_luanchOptions
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
}
}
}
return self;
}
@@ -39,7 +79,46 @@
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)resumePush:(CDVInvokedUrlCommand*)command{
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else {
//categories nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
#else
//categories nil
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
#endif
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result;
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
result=@(0);
}else{
result=@(1);
}
CDVPluginResult * pushResult=[self pluginResultForValue:result];
if (pushResult) {
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
} else {
[self failWithCallbackID:command.callbackId];
}}
-(void)setTags:(CDVInvokedUrlCommand *)command{
@@ -164,6 +243,19 @@
- (void)succeedWithPluginResult:(CDVPluginResult *)result withCallbackID:(NSString *)callbackID {
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
}
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command{
//
NSArray *argument=command.arguments;
if ([argument count]<1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge=[argument objectAtIndex:0];
[UIApplication sharedApplication].applicationIconBadgeNumber=[badge intValue];
}
- (CDVPluginResult *)pluginResultForValue:(id)value {
CDVPluginResult *result;
@@ -194,20 +286,57 @@
- (void)networkDidReceiveMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
NSLog(@"%@",userInfo);
//NSLog(@"%@",userInfo);
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@",jsonString);
//NSLog(@"%@",jsonString);
dispatch_async(dispatch_get_main_queue(), ^{
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
});
}
-(void)networkDidReceiveNotification:(id)notification{
NSError *error;
NSDictionary *userInfo = [notification object];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive:
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
});
}
break;
case UIApplicationStateInactive:
case UIApplicationStateBackground:
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
break;
default:
//do nothing
break;
}
}
@end

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>APP_KEY</key>
<string>7d431e42dfa6a6d693ac2d04</string>
<key>CHANNEL</key>
<string>Subscription</string>
</dict>
<dict>
<key>APP_KEY</key>
<string></string>
<key>CHANNEL</key>
<string>Subscription</string>
</dict>
</plist>

View File

@@ -4,7 +4,7 @@
//
// Created by JPush on 12-8-15.
// Copyright (c) 2012年 HXHG. All rights reserved.
// Version: 1.8.1
// Version: 1.8.8
@class CLRegion;
@class UILocalNotification;
@@ -155,12 +155,6 @@ extern NSString *const kJPFServiceErrorNotification; // 错误提示
+ (void)resetBadge;
#pragma - mark 获取用户标示符
/**
* get the UDID
*/
+ (NSString *)openUDID DEPRECATED_ATTRIBUTE; // UDID
/**
* get RegistrationID
*/

Binary file not shown.

Binary file not shown.

View File

@@ -1,8 +1,14 @@
var JPushPlugin = function(){
};
//private plugin function
JPushPlugin.prototype.receiveMessage={}
JPushPlugin.prototype.openNotification={}
JPushPlugin.prototype.receiveNotification={}
JPushPlugin.prototype.isPlatformIOS = function(){
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
}
@@ -35,6 +41,11 @@ JPushPlugin.prototype.beginLogPageView = function(pageName,duration){
this.call_native( "beginLogPageView",[pageName,duration],null);
}
}
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge){
if(this.isPlatformIOS()){
this.call_native( "setApplicationIconBadgeNumber",[badge],null);
}
}
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
try{
@@ -135,8 +146,10 @@ JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
try{
console.log("JPushPlugin:receiveMessageInAndroidCallback");
var bToObj = JSON.parse(data);
this.receiveMessage=bToObj
cordova.fireDocumentEvent('jpush.receiveMessage',null);
//console.log(data);
//ecvar bToObj=JSON.parse(data);
//var message = bToObj.message;
//var extras = bToObj.extras;
@@ -149,11 +162,41 @@ JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
console.log("JPushPlugin:pushCallback "+exception);
}
}
//
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
try{
console.log("JPushPlugin:openNotificationInAndroidCallback");
console.log(data);
console.log("JPushPlugin:openNotificationInAndroidCallback");
var bToObj = JSON.parse(data);
this.openNotification=bToObj;
cordova.fireDocumentEvent('jpush.openNotification',null);
//console.log(data);
//var bToObj = JSON.parse(data);
//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);
}
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data){
try{
console.log("JPushPlugin:receiveNotificationInAndroidCallback");
var bToObj = JSON.parse(data);
this.receiveNotification=bToObj;
cordova.fireDocumentEvent('jpush.receiveNotification',null);
//console.log(data);
//var bToObj = JSON.parse(data);
//var alert = bToObj.alert;
//var extras = bToObj.extras;
@@ -193,10 +236,9 @@ JPushPlugin.prototype.stopPush = function(){
}
JPushPlugin.prototype.resumePush = function(){
if(device.platform == "Android") {
data=[]
this.call_native("resumePush",data,null);
}
}
JPushPlugin.prototype.setDebugMode = function(mode){
if(device.platform == "Android") {
@@ -211,6 +253,13 @@ JPushPlugin.prototype.clearAllNotification = function(){
}
}
JPushPlugin.prototype.clearNotificationById = function(notificationId){
if(device.platform == "Android") {
data=[]
this.call_native("clearNotificationById",[notificationId],null);
}
}
JPushPlugin.prototype.setLatestNotificationNum = function(num){
if(device.platform == "Android") {
this.call_native("setLatestNotificationNum",[num],null);
@@ -218,17 +267,22 @@ JPushPlugin.prototype.setLatestNotificationNum = function(num){
}
JPushPlugin.prototype.isPushStopped = function(callback){
if(device.platform == "Android") {
data=[];
this.call_native("isPushStopped",data,callback)
}
}
JPushPlugin.prototype.init = function(){
if(device.platform == "Android") {
data=[];
this.call_native("init",data,null);
}
if(this.isPlatformIOS()){
var data=[];
this.call_native("initial",data,null);
}else{
data=[];
this.call_native("init",data,null);
}
}
JPushPlugin.prototype.setDebugMode = function(mode){
@@ -254,6 +308,13 @@ JPushPlugin.prototype.clearLocalNotifications = function(){
}
}
JPushPlugin.prototype.reportNotificationOpened = function(msgID){
if(device.platform == "Android") {
this.call_native("reportNotificationOpened",[msgID],null);
}
}
//iOS single