Compare commits

...

11 Commits

Author SHA1 Message Date
Hevin 1c3228848b build: v3.2.7 2017-10-11 14:49:07 +08:00
huangminlinux 585e2a5084 fix open local notification to launch app event bug 2017-10-11 14:28:56 +08:00
huangminlinux c726477cfb remove jpush.startLocalNotification event in iOS docs 2017-10-11 11:29:40 +08:00
huangminlinux 3f00143a5a update doc remove startLocalNotification event 2017-10-11 11:26:46 +08:00
huangminlinux f5ea2b5b10 ios add jpush.receiveRegistrationId event 2017-10-11 11:15:13 +08:00
Hevin 266d0cb28f Add JPushEventReceiver in manifest 2017-09-28 10:22:40 +08:00
Hevin 9f156727e7 Remove unused code 2017-09-26 17:51:25 +08:00
Hevin 155f1e2f6c Update Android SDK to v3.0.9 2017-09-26 17:48:18 +08:00
Hevin 9680e685e3 Remove unused console.log 2017-09-25 12:33:08 +08:00
Hevin 2eefd1c247 Fixed android api doc 2017-09-25 12:32:27 +08:00
Hevin fa256bfb46 Format api doc 2017-09-23 09:11:21 +08:00
12 changed files with 205 additions and 242 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
# JPush PhoneGap / Cordova Plugin # JPush PhoneGap / Cordova Plugin
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin) [![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
[![release](https://img.shields.io/badge/release-3.2.4-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![release](https://img.shields.io/badge/release-3.2.7-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin) [![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
+5 -30
View File
@@ -1,12 +1,7 @@
# Android API 简介 # Android API 简介
- [注册成功事件](#注册成功事件) - [注册成功事件](#注册成功事件)
- [接收通知时获得通知的内容](#接收通知时获得通知的内容)
- [打开通知时获得通知的内容](#打开通知时获得通知的内容)
- [收到自定义消息时获取消息的内容](#收到自定义消息时获取消息的内容)
- [获取集成日志(同时适用于 iOS](#获取集成日志同时适用于-ios) - [获取集成日志(同时适用于 iOS](#获取集成日志同时适用于-ios)
- [接收消息和点击通知事件](#接收消息和点击通知事件)
- [统计分析](#统计分析)
- [清除通知](#清除通知) - [清除通知](#清除通知)
- [设置允许推送时间](#设置允许推送时间) - [设置允许推送时间](#设置允许推送时间)
- [设置通知静默时间](#设置通知静默时间) - [设置通知静默时间](#设置通知静默时间)
@@ -27,31 +22,6 @@ document.addEventListener('jpush.receiveRegistrationId', function (event) {
}, false) }, false)
``` ```
## 接收通知时获得通知的内容
- 内容:
window.JPush.receiveNotification.alert
- 标题:
window.JPush.receiveNotification.title
- 附加字段:
window.JPush.receiveNotification.extras.yourKey
## 打开通知时获得通知的内容
- 内容:
window.JPush.openNotification.alert
- 标题:
window.JPush.openNotification.title
- 附加字段
window.JPush.openNotification.extras.yourKey
## 收到自定义消息时获取消息的内容
- 内容:
window.JPush.receiveMessage.message
- 附加字段:
window.JPush.receiveMessage.extras.yourKey
## 获取集成日志(同时适用于 iOS) ## 获取集成日志(同时适用于 iOS)
### API - setDebugMode ### API - setDebugMode
@@ -159,6 +129,11 @@ window.JPush.setSilenceTime(startHour, startMinute, endHour, endMinute)
## 通知栏样式定制 ## 通知栏样式定制
目前 REST API 与极光控制台均已支持「大文本通知栏样」、「文本条目通知栏样式」和「大图片通知栏样式」。可直接推送对应样式
的通知。
此外也能够通过设置 Notification 的 flag 来控制通知提醒方式,具体用法可参考 [后台 REST API](https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#notification)。
### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder ### API - setBasicPushNotificationBuilder, setCustomPushNotificationBuilder
当用户需要定制默认的通知栏样式时,则可调用此方法。 当用户需要定制默认的通知栏样式时,则可调用此方法。
+2
View File
@@ -528,11 +528,13 @@ document.addEventListener("jpush.receiveMessage", function (event) {
在 iOS 中,返回值为 0 时,代表系统设置中关闭了推送;大于 0 时,代表打开了推送,且能够根据返回值判断具体通知形式: 在 iOS 中,返回值为 0 时,代表系统设置中关闭了推送;大于 0 时,代表打开了推送,且能够根据返回值判断具体通知形式:
```js
UIRemoteNotificationTypeNone = 0, // 0 UIRemoteNotificationTypeNone = 0, // 0
UIRemoteNotificationTypeBadge = 1 << 0, // 1 UIRemoteNotificationTypeBadge = 1 << 0, // 1
UIRemoteNotificationTypeSound = 1 << 1, // 2 UIRemoteNotificationTypeSound = 1 << 1, // 2
UIRemoteNotificationTypeAlert = 1 << 2, // 4 UIRemoteNotificationTypeAlert = 1 << 2, // 4
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3 // 8 UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3 // 8
```
#### 代码示例 #### 代码示例
-6
View File
@@ -437,9 +437,7 @@ window.JPush.clearAllLocalNotifications()
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。 监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
### 点击本地通知横幅启动 App
监听 `jpush.startLocalNotification` 事件。
## 页面的统计 ## 页面的统计
@@ -726,10 +724,6 @@ window.JPush.getUserNotificationSettings(callback)
[获取自定义消息内容](#获取自定义消息内容) [获取自定义消息内容](#获取自定义消息内容)
### jpush.startLocalNotification
[点击本地通知横幅启动 App](#点击本地通知横幅启动-app)
### jpush.receiveLocalNotification ### jpush.receiveLocalNotification
[iOS 10 before 收到本地通知](#ios-10-before-收到本地通知) [iOS 10 before 收到本地通知](#ios-10-before-收到本地通知)
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "jpush-phonegap-plugin", "name": "jpush-phonegap-plugin",
"version": "3.2.4", "version": "3.2.7",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",
+21 -6
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="jpush-phonegap-plugin" id="jpush-phonegap-plugin"
version="3.2.4"> version="3.2.7">
<name>JPush</name> <name>JPush</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
@@ -72,20 +72,22 @@
<config-file target="AndroidManifest.xml" parent="/manifest"> <config-file target="AndroidManifest.xml" parent="/manifest">
<!-- Required 一些系统要求的权限,如访问网络等--> <!-- Required 一些系统要求的权限,如访问网络等-->
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
<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" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature" />
</config-file> </config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application"> <config-file target="AndroidManifest.xml" parent="/manifest/application">
@@ -187,12 +189,25 @@
android:name="cn.jpush.android.service.AlarmReceiver" android:name="cn.jpush.android.service.AlarmReceiver"
android:exported="false" /> android:exported="false" />
<!-- since 3.0.9 Required SDK 核心功能-->
<provider
android:authorities="$PACKAGE_NAME.DataProvider"
android:name="cn.jpush.android.service.DataProvider"
android:exported="true" />
<receiver android:name="cn.jiguang.cordova.push.JPushEventReceiver">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="$PACKAGE_NAME"></category>
</intent-filter>
</receiver>
<!-- Required. Enable it you can get statistics data with channel --> <!-- 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_CHANNEL" android:value="developer-default" />
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" /> <meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
</config-file> </config-file>
<source-file src="src/android/libs/jpush-android-3.0.8.jar" target-dir="libs" /> <source-file src="src/android/libs/jpush-android-3.0.9.jar" target-dir="libs" />
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jiguang/cordova/push" /> <source-file src="src/android/MyReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" /> <source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
+4 -27
View File
@@ -39,15 +39,12 @@ import cn.jpush.android.service.JPushMessageReceiver;
public class JPushPlugin extends CordovaPlugin { public class JPushPlugin extends CordovaPlugin {
private ExecutorService threadPool = Executors.newFixedThreadPool(1); private static final String TAG = JPushPlugin.class.getSimpleName();
private Context mContext; private Context mContext;
private static JPushPlugin instance; private static JPushPlugin instance;
private static Activity cordovaActivity; private static Activity cordovaActivity;
private static String TAG = "JPushPlugin";
private static boolean isStatisticsOpened = false; // 是否开启统计分析功能
static String notificationTitle; static String notificationTitle;
static String notificationAlert; static String notificationAlert;
@@ -85,16 +82,7 @@ public class JPushPlugin extends CordovaPlugin {
} }
} }
public void onPause(boolean multitasking) {
if (isStatisticsOpened && multitasking) {
JPushInterface.onPause(this.cordova.getActivity());
}
}
public void onResume(boolean multitasking) { public void onResume(boolean multitasking) {
if (isStatisticsOpened && multitasking) {
JPushInterface.onResume(this.cordova.getActivity());
}
if (openNotificationAlert != null) { if (openNotificationAlert != null) {
notificationAlert = null; notificationAlert = null;
transmitNotificationOpen(openNotificationTitle, openNotificationAlert, transmitNotificationOpen(openNotificationTitle, openNotificationAlert,
@@ -252,7 +240,7 @@ public class JPushPlugin extends CordovaPlugin {
@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 {
threadPool.execute(new Runnable() { cordova.getThreadPool().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@@ -644,17 +632,6 @@ public class JPushPlugin extends CordovaPlugin {
JPushInterface.clearLocalNotifications(this.cordova.getActivity()); JPushInterface.clearLocalNotifications(this.cordova.getActivity());
} }
/**
* 决定是否启用统计分析功能。
*/
void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
try {
isStatisticsOpened = data.getBoolean(0);
} catch (JSONException e) {
e.printStackTrace();
}
}
/** /**
* 设置通知静默时间 * 设置通知静默时间
* http://docs.jpush.io/client/android_api/#api_5 * http://docs.jpush.io/client/android_api/#api_5
Binary file not shown.
Binary file not shown.
+170 -156
View File
@@ -1,156 +1,170 @@
// //
// AppDelegate+JPush.m // AppDelegate+JPush.m
// delegateExtention // delegateExtention
// //
// Created by 张庆贺 on 15/8/3. // Created by 张庆贺 on 15/8/3.
// Copyright (c) 2015年 JPush. All rights reserved. // Copyright (c) 2015年 JPush. All rights reserved.
// //
#import "AppDelegate+JPush.h" #import "AppDelegate+JPush.h"
#import "JPushPlugin.h" #import "JPushPlugin.h"
#import <objc/runtime.h> #import <objc/runtime.h>
#import <AdSupport/AdSupport.h> #import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h> #import <UserNotifications/UserNotifications.h>
#import "JPushDefine.h" #import "JPushDefine.h"
@implementation AppDelegate (JPush) @implementation AppDelegate (JPush)
+(void)load{ +(void)load{
Method origin1; Method origin1;
Method swizzle1; Method swizzle1;
origin1 = class_getInstanceMethod([self class],@selector(init)); origin1 = class_getInstanceMethod([self class],@selector(init));
swizzle1 = class_getInstanceMethod([self class], @selector(init_plus)); swizzle1 = class_getInstanceMethod([self class], @selector(init_plus));
method_exchangeImplementations(origin1, swizzle1); method_exchangeImplementations(origin1, swizzle1);
} }
-(instancetype)init_plus{ -(instancetype)init_plus{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil];
return [self init_plus]; return [self init_plus];
} }
-(void)fireOpenNotification:(NSTimer*)timer{ -(void)fireOpenNotification:(NSTimer*)timer{
if (SharedJPushPlugin) { if (SharedJPushPlugin) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]]; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[timer.userInfo toJsonString]];
[timer invalidate]; [timer invalidate];
} }
} }
NSDictionary *_launchOptions; NSDictionary *_launchOptions;
-(void)applicationDidLaunch:(NSNotification *)notification{ -(void)applicationDidLaunch:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushSDKDidLoginNotification) name:kJPFNetworkDidLoginNotification object:nil];
if (notification) {
if (notification.userInfo) { if (notification) {
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (notification.userInfo) {
if (userInfo1.count > 0) {
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES]; if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
} [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:)
userInfo:[notification.userInfo
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] repeats:YES];
if (userInfo2.count > 0) { }
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES];
} if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
} UILocalNotification *localNotification = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[JPUSHService setDebugMode];
NSDictionary* localNotificationEvent = @{@"content":localNotification.alertBody,
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"]; @"badge": @(localNotification.applicationIconBadgeNumber),
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; @"extras":localNotification.userInfo,
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay]; };
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:localNotificationEvent repeats:YES];
_launchOptions = notification.userInfo; }
}
if (![delay boolValue]) {
[self startJPushSDK]; [JPUSHService setDebugMode];
}
} NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
} NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
-(void)startJPushSDK{
[self registerForRemoteNotification]; _launchOptions = notification.userInfo;
[JPushPlugin setupJPushSDK:_launchOptions];
} if (![delay boolValue]) {
[self startJPushSDK];
-(void)registerForRemoteNotification{ }
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) { }
#ifdef NSFoundationVersionNumber_iOS_9_x_Max }
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound; -(void)startJPushSDK{
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; [self registerForRemoteNotification];
#endif [JPushPlugin setupJPushSDK:_launchOptions];
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { }
//可以添加自定义categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | - (void)jpushSDKDidLoginNotification {
UIUserNotificationTypeSound | NSDictionary *event = @{@"registrationId": JPUSHService.registrationID};
UIUserNotificationTypeAlert) [JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
categories:nil]; }
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
//categories 必须为nil -(void)registerForRemoteNotification{
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
UIRemoteNotificationTypeSound | #ifdef NSFoundationVersionNumber_iOS_9_x_Max
UIRemoteNotificationTypeAlert) JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
categories:nil]; entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
} [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
} #endif
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { //可以添加自定义categories
[JPUSHService registerDeviceToken:deviceToken]; [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
} UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ categories:nil];
[JPUSHService handleRemoteNotification:userInfo]; } else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
//categories 必须为nil
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
} UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ categories:nil];
[JPUSHService handleRemoteNotification:userInfo]; }
NSString *eventName; }
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateInactive: - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
eventName = JPushDocumentEvent_OpenNotification; [JPUSHService registerDeviceToken:deviceToken];
break; }
case UIApplicationStateActive:
eventName = JPushDocumentEvent_ReceiveNotification; -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
break; [JPUSHService handleRemoteNotification:userInfo];
case UIApplicationStateBackground:
eventName = JPushDocumentEvent_BackgroundNotification; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
break; }
default:
break; -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
} [JPUSHService handleRemoteNotification:userInfo];
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]]; NSString *eventName;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ switch ([UIApplication sharedApplication].applicationState) {
completionHandler(UIBackgroundFetchResultNewData); case UIApplicationStateInactive:
}); eventName = JPushDocumentEvent_OpenNotification;
} break;
case UIApplicationStateActive:
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{ eventName = JPushDocumentEvent_ReceiveNotification;
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; break;
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; case UIApplicationStateBackground:
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); eventName = JPushDocumentEvent_BackgroundNotification;
} break;
default:
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{ break;
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo]; }
@try { [JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
} @catch (NSException *exception) { } completionHandler(UIBackgroundFetchResultNewData);
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"]; });
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]]; }
completionHandler();
} -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo]; completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
} }
- (void)applicationWillEnterForeground:(UIApplication *)application { -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
// [application setApplicationIconBadgeNumber:0]; NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
// [application cancelAllLocalNotifications]; @try {
} [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
} @catch (NSException *exception) { }
- (void)applicationDidEnterBackground:(UIApplication *)application { [userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
} completionHandler();
}
@end
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// [application setApplicationIconBadgeNumber:0];
// [application cancelAllLocalNotifications];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
@end
+1 -2
View File
@@ -27,7 +27,6 @@ static NSString *const JPushDocumentEvent_OpenNotification = @"openNoti
static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification"; static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification";
static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias"; static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage"; static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
static NSString *const JPushDocumentEvent_StartLocalNotification = @"startLocalNotification";
static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification"; static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification";
static NSString *const JPushDocumentEvent_receiveRegistrationId = @"receiveRegistrationId";
-13
View File
@@ -311,21 +311,18 @@ JPushPlugin.prototype.receiveRegistrationIdInAndroidCallback = function (data) {
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) { JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
data = JSON.stringify(data) data = JSON.stringify(data)
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
this.receiveMessage = JSON.parse(data) this.receiveMessage = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage) cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
} }
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) { JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
data = JSON.stringify(data) data = JSON.stringify(data)
console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
this.openNotification = JSON.parse(data) this.openNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.openNotification', this.openNotification) cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
} }
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) { JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
data = JSON.stringify(data) data = JSON.stringify(data)
console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
this.receiveNotification = JSON.parse(data) this.receiveNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification) cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
} }
@@ -368,16 +365,6 @@ JPushPlugin.prototype.reportNotificationOpened = function (msgID) {
} }
} }
/**
*是否开启统计分析功能,用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器上,
*在 Portal 上展示给开发者。
*/
JPushPlugin.prototype.setStatisticsOpen = function (mode) {
if (device.platform === 'Android') {
this.callNative('setStatisticsOpen', [mode], null)
}
}
/** /**
* 用于在 Android 6.0 及以上系统,申请一些权限 * 用于在 Android 6.0 及以上系统,申请一些权限
* 具体可看:http://docs.jpush.io/client/android_api/#android-60 * 具体可看:http://docs.jpush.io/client/android_api/#android-60