Compare commits

..

14 Commits

Author SHA1 Message Date
Hevin edf29bbc8d Merge branch 'dev' 2017-09-28 10:25:03 +08:00
Hevin ae54960da4 Merge branch 'dev' 2017-09-26 18:28:44 +08:00
Hevin ea6011635f Merge branch 'dev' 2017-09-25 12:32:36 +08:00
Hevin 0829104534 Merge branch 'dev' 2017-09-23 09:11:34 +08:00
Hevin 592d5a5fb9 Merge branch 'dev' 2017-09-22 21:16:11 +08:00
Hevin 4753174bda Merge branch 'dev' 2017-09-22 20:24:21 +08:00
Hevin 3f077e32fd Merge branch 'dev' 2017-09-19 14:33:24 +08:00
Hevin 5c569d00da Merge branch 'dev' 2017-09-08 14:32:18 +08:00
Hevin c5f7963425 Merge branch 'dev' 2017-07-21 14:15:57 +08:00
Hevin a4eaf51455 Merge branch 'dev' 2017-07-21 14:00:30 +08:00
Hevin 04fae7d538 Merge branch 'dev' 2017-07-12 10:16:49 +08:00
Hevin 8e087e102a Merge branch 'dev' 2017-07-07 11:26:20 +08:00
Hevin 35c09c0c92 Merge branch 'dev' 2017-07-04 17:51:51 +08:00
Hevin f0a87962e7 Merge branch 'dev' 2017-06-30 15:44:35 +08:00
6 changed files with 167 additions and 174 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.7-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![release](https://img.shields.io/badge/release-3.2.6-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,7 +437,9 @@ window.JPush.clearAllLocalNotifications()
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。 监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
### 点击本地通知横幅启动 App
监听 `jpush.startLocalNotification` 事件。
## 页面的统计 ## 页面的统计
@@ -724,6 +726,10 @@ 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.7", "version": "3.2.6",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",
+1 -1
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin" id="jpush-phonegap-plugin"
version="3.2.7"> version="3.2.6">
<name>JPush</name> <name>JPush</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
+156 -170
View File
@@ -1,170 +1,156 @@
// //
// 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) { if (notification.userInfo) {
if (notification.userInfo) { NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) {
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES];
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) }
userInfo:[notification.userInfo
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] repeats:YES]; NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
} 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,
@"badge": @(localNotification.applicationIconBadgeNumber), NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
@"extras":localNotification.userInfo, NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
}; 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]) {
[JPUSHService setDebugMode]; [self startJPushSDK];
}
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"]; }
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; }
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
-(void)startJPushSDK{
_launchOptions = notification.userInfo; [self registerForRemoteNotification];
[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];
-(void)startJPushSDK{ entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[self registerForRemoteNotification]; [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
[JPushPlugin setupJPushSDK:_launchOptions]; #endif
} }else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories
- (void)jpushSDKDidLoginNotification { [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
NSDictionary *event = @{@"registrationId": JPUSHService.registrationID}; UIUserNotificationTypeSound |
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]]; UIUserNotificationTypeAlert)
} categories:nil];
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
-(void)registerForRemoteNotification{ //categories 必须为nil
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) { [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
#ifdef NSFoundationVersionNumber_iOS_9_x_Max UIRemoteNotificationTypeSound |
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; UIRemoteNotificationTypeAlert)
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound; categories:nil];
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; }
#endif }
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//可以添加自定义categories - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | [JPUSHService registerDeviceToken:deviceToken];
UIUserNotificationTypeSound | }
UIUserNotificationTypeAlert)
categories:nil]; -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){ [JPUSHService handleRemoteNotification:userInfo];
//categories 必须为nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
UIRemoteNotificationTypeSound | }
UIRemoteNotificationTypeAlert)
categories:nil]; -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
} [JPUSHService handleRemoteNotification:userInfo];
} NSString *eventName;
switch ([UIApplication sharedApplication].applicationState) {
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { case UIApplicationStateInactive:
[JPUSHService registerDeviceToken:deviceToken]; eventName = JPushDocumentEvent_OpenNotification;
} break;
case UIApplicationStateActive:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ eventName = JPushDocumentEvent_ReceiveNotification;
[JPUSHService handleRemoteNotification:userInfo]; break;
case UIApplicationStateBackground:
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; eventName = JPushDocumentEvent_BackgroundNotification;
} break;
default:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{ break;
[JPUSHService handleRemoteNotification:userInfo]; }
NSString *eventName; [JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]];
switch ([UIApplication sharedApplication].applicationState) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
case UIApplicationStateInactive: completionHandler(UIBackgroundFetchResultNewData);
eventName = JPushDocumentEvent_OpenNotification; });
break; }
case UIApplicationStateActive:
eventName = JPushDocumentEvent_ReceiveNotification; -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
break; NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
case UIApplicationStateBackground: [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
eventName = JPushDocumentEvent_BackgroundNotification; completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
break; }
default:
break; -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
} NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
[JPushPlugin fireDocumentEvent:eventName jsString:[userInfo toJsonString]]; @try {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
completionHandler(UIBackgroundFetchResultNewData); } @catch (NSException *exception) { }
}); [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];
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); [[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo];
} }
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{ - (void)applicationWillEnterForeground:(UIApplication *)application {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo]; // [application setApplicationIconBadgeNumber:0];
@try { // [application cancelAllLocalNotifications];
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"]; }
} @catch (NSException *exception) { }
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"]; - (void)applicationDidEnterBackground:(UIApplication *)application {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]]; // [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
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
+2 -1
View File
@@ -27,6 +27,7 @@ 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";