Compare commits

...

6 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
6 changed files with 181 additions and 167 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.5-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)
-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.5", "version": "3.2.7",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",
+8 -1
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin" id="jpush-phonegap-plugin"
version="3.2.5"> version="3.2.7">
<name>JPush</name> <name>JPush</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
@@ -195,6 +195,13 @@
android:name="cn.jpush.android.service.DataProvider" android:name="cn.jpush.android.service.DataProvider"
android:exported="true" /> 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" />
+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";