iOS - update

1.更新 SDK
2.删除过期方法
3.更新过期方法
4.删除重复方法
5.发现并修复 bug
6.优化代码
7.更新 doc
This commit is contained in:
pikacode 2016-11-29 17:48:07 +08:00
parent 1cbd1b6e9d
commit 6d0dce371e
13 changed files with 629 additions and 742 deletions

View File

@ -53,8 +53,8 @@
### iOS
#### PushConfig.plist 文件中的字段都是什么意思?
- APP_KEY:应用标识。
- CHANNEL:渠道标识。
- Appkey:应用标识。
- Channel:渠道标识。
- IsProduction是否生产环境。
- IsIDFA是否使用 IDFA 启动 SDK。

View File

@ -267,7 +267,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### event - jpush.backgroundNotification
应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification)
应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](https://docs.jiguang.cn/jpush/client/iOS/ios_new_fetures/#ios-7-background-remote-notification)
#### 代码示例
@ -296,20 +296,6 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
"_j_msgid":154604475
}
#### API - receiveMessageIniOSCallback
用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
不推荐使用回调函数
##### 接口定义
JPushPlugin.prototype.receiveMessageIniOSCallback(data)
##### 参数说明
- data: 是一个 js 字符串使用如下代码解析js 具体 key 根据应用内消息来确定:
var bToObj = JSON.parse(data);
## 获取自定义消息内容

View File

@ -1,35 +1,39 @@
## iOS 手动安装
- 下载 JPush PhoneGap Plugin 插件,并解压
不建议使用手动安装,请参照 README.md 进行自动安装。
- 将 [/src/ios](/src/ios) 文件夹及内容在 xcode 中拖到你的工程里,并配置 [/src/ios/PushConfig.plist](/src/ios/PushConfig.plist) 中相应参数:
1. 下载 JPush PhoneGap Plugin 插件,并解压
2. 将 [/src/ios](/src/ios) 文件夹及内容在 xcode 中拖到你的工程里,并配置 [/src/ios/PushConfig.plist](/src/ios/PushConfig.plist) 中相应参数:
APP_KEY 应用标识
CHANNEL 渠道标识
IsProduction是否生产环境
IsIDFA 是否使用 IDFA 启动 sdk
Appkey 应用标识
Channel 渠道标识
IsProduction是否生产环境
IsIDFA 是否使用 IDFA 启动 sdk
3. 打开 xcode点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
- 打开 xcode点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
AdSupport.framework
libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
UserNotifications.framework
libresolv.tbd
4. 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
CFNetwork.framework
CoreFoundation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
Foundation.framework
UIKit.framework
AdSupport.framework
libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
```xml
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" />
<param name="onload" value="true" />
</feature>
```
5. 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
6. 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
- 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
```xml
<script type="text/javascript" src="JPushPlugin.js"></script>
```
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" />
<param name="onload" value="true" />
</feature>
- 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
- 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
<script type="text/javascript" src="JPushPlugin.js"></script>

View File

@ -32,11 +32,11 @@
<header-file src="src/ios/Plugins/JPushPlugin.h" />
<source-file src="src/ios/Plugins/JPushPlugin.m" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.1.9.a" framework="true" />
<header-file src="src/ios/Plugins/JPushDefine.h" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h" />
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.2.0.a" framework="true" />
<resource-file src="src/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
@ -49,9 +49,10 @@
<framework src="libz.tbd" weak="true" />
<framework src="AdSupport.framework" weak="true" />
<framework src="UserNotifications.framework" weak="true" />
<framework src="libresolv.tbd" weak="true" />
<config-file target="*PushConfig.plist" parent="APP_KEY">
<config-file target="*PushConfig.plist" parent="Appkey">
<string>$API_KEY</string>
</config-file>
</platform>

View File

@ -1,15 +1,15 @@
//
// AppDelegate+JPush.h
// delegateExtention
//
// Created by 张庆贺 on 15/8/3.
// Copyright (c) 2015年 JPush. All rights reserved.
//
#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "JPUSHService.h"
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
-(void)registerForIos10RemoteNotification;
@end
//
// AppDelegate+JPush.h
// delegateExtention
//
// Created by pikacode@qq.com on 15/8/3.
// Copyright (c) 2015年 JPush. All rights reserved.
//
#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "JPUSHService.h"
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
-(void)registerForRemoteNotification;
@end

View File

@ -1,101 +1,132 @@
//
// AppDelegate+JPush.m
// delegateExtention
//
// Created by on 15/8/3.
// Copyright (c) 2015 JPush. All rights reserved.
//
#import "AppDelegate+JPush.h"
#import "JPushPlugin.h"
#import <objc/runtime.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
@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) {
[self registerForIos10RemoteNotification];
[JPushPlugin setLaunchOptions:notification.userInfo];
}
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService registerDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
[JPUSHService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// [application setApplicationIconBadgeNumber:0];
// [application cancelAllLocalNotifications];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
[userInfo setValue:kJPushPluginiOS10ForegroundReceiveNotification forKey:@"JPushNotificationType"];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ForegroundReceiveNotification object:userInfo];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
@try {
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
} @catch (NSException *exception) { }
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
[userInfo setValue:kJPushPluginiOS10ClickNotification forKey:@"JPushNotificationType"];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ClickNotification object:userInfo];
completionHandler();
}
-(void)registerForIos10RemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
#endif
}
}
@end
//
// AppDelegate+JPush.m
// delegateExtention
//
// Created by pikacode@qq.com on 15/8/3.
// Copyright (c) 2015 JPush. All rights reserved.
//
#import "AppDelegate+JPush.h"
#import "JPushPlugin.h"
#import <objc/runtime.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
#import "JPushDefine.h"
@implementation AppDelegate (JPush)
+(void)load{
Method origin1;
Method swizzle1;
origin1 = class_getInstanceMethod([self class],@selector(init));
swizzle1 = class_getInstanceMethod([self class], @selector(init_plus));
method_exchangeImplementations(origin1, swizzle1);
}
-(instancetype)init_plus{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil];
return [self init_plus];
}
-(void)applicationDidLaunch:(NSNotification *)notification{
if (notification) {
if (notification.userInfo) {
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) {
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo1 toJsonString]];
}
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (userInfo2.count > 0) {
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenLocalNotification jsString:[userInfo1 toJsonString]];
}
}
[JPUSHService setDebugMode];
[self registerForRemoteNotification];
[JPushPlugin setupJPushSDK:notification.userInfo];
}
}
-(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;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
#endif
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
//categories nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService registerDeviceToken:deviceToken];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService handleRemoteNotification:userInfo];
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
[JPUSHService handleRemoteNotification:userInfo];
NSString *eventName;
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateInactive:
eventName = JPushDocumentEvent_OpenNotification;
break;
case UIApplicationStateActive:
eventName = JPushDocumentEvent_ReceiveNotification;
break;
case UIApplicationStateBackground:
eventName = JPushDocumentEvent_BackgoundNotification;
break;
default:
break;
}
[SharedJPushPlugin jpushFireDocumentEvent:eventName jsString:[userInfo toJsonString]];
completionHandler(UIBackgroundFetchResultNewData);
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
@try {
[userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
} @catch (NSException *exception) { }
[userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
completionHandler();
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveLocalNotification object:notification.userInfo];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// [application setApplicationIconBadgeNumber:0];
// [application cancelAllLocalNotifications];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
@end

View File

@ -0,0 +1,31 @@
//
// ConstantDef.h
// jmessage
//
// Created by pikacode@qq.com on 16/1/19.
//
//
#ifndef ConstantDef_h
#define ConstantDef_h
#endif /* ConstantDef_h */
#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
static NSString *const JPushConfig_Appkey = @"Appkey";
static NSString *const JPushConfig_Channel = @"Channel";
static NSString *const JPushConfig_IsProduction = @"IsProduction";
static NSString *const JPushConfig_IsIDFA = @"IsIDFA";
static NSString *const JPushConfig_FileName = @"PushConfig";
static NSString *const JPushDocumentEvent_ReceiveNotification = @"receiveNotification";
static NSString *const JPushDocumentEvent_OpenNotification = @"openNotification";
static NSString *const JPushDocumentEvent_BackgoundNotification = @"backgoundNotification";
static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
static NSString *const JPushDocumentEvent_OpenLocalNotification = @"openLocalNotification";

View File

@ -1,80 +1,91 @@
//
// PushTalkPlugin.h
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import <Cordova/CDV.h>
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
#define kJPushPluginiOS10ForegroundReceiveNotification @"kJPushPluginiOS10ForegroundReceiveNotification"
#define kJPushPluginiOS10ClickNotification @"kJPushPluginiOS10ClickNotification"
@interface JPushPlugin : CDVPlugin{
}
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions;
//以下为js中可调用接口
//设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
//页面统计
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
//设置角标到服务器,服务器下一次发消息时,会设置成这个值
//本接口不会改变应用本地的角标值.
-(void)setBadge:(CDVInvokedUrlCommand*)command;
//相当于 [setBadge:0]
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
//应用本地的角标值设置/获取
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
//停止与恢复推送
-(void)stopPush:(CDVInvokedUrlCommand*)command;
-(void)resumePush:(CDVInvokedUrlCommand*)command;
-(void)isPushStopped:(CDVInvokedUrlCommand*)command;
//开关日志
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
-(void)setLogOFF:(CDVInvokedUrlCommand*)command;
-(void)crashLogON:(CDVInvokedUrlCommand*)command;
//本地推送
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
//地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
//ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command;
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
/*
* js中可监听到的事件
* jpush.openNotification app
* jpush.setTagsWithAlias
* jpush.receiveMessage
* jpush.receiveNotification
* jpush.backgroundNotification
*/
@end
//
// PushTalkPlugin.h
// PushTalk
//
// Created by pikacode@qq.com on 13-12-13.
//
//
#import <Cordova/CDV.h>
@interface JPushPlugin : CDVPlugin{
}
//以下为js中可调用接口
//设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)setAlias:(CDVInvokedUrlCommand*)command;
//获取 RegistrationID
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
//页面统计
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
//设置角标到服务器,服务器下一次发消息时,会设置成这个值
//本接口不会改变应用本地的角标值.
-(void)setBadge:(CDVInvokedUrlCommand*)command;
//相当于 [setBadge:0]
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
//应用本地的角标值设置/获取
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
//停止与恢复推送
-(void)stopPush:(CDVInvokedUrlCommand*)command;
-(void)resumePush:(CDVInvokedUrlCommand*)command;
-(void)isPushStopped:(CDVInvokedUrlCommand*)command;
//开关日志
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
-(void)setLogOFF:(CDVInvokedUrlCommand*)command;
-(void)crashLogON:(CDVInvokedUrlCommand*)command;
//本地推送
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
//地理位置上报 [latitude,longitude]
-(void)setLocation:(CDVInvokedUrlCommand*)command;
//检查用户的推送设置情况
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
//ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command;
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
/*
* js中可监听到的事件
* jpush.openNotification app
* jpush.setTagsWithAlias
* jpush.receiveMessage
* jpush.receiveNotification
* jpush.backgroundNotification
*/
# pragma mark - private
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+(void)setupJPushSDK:(NSDictionary*)userInfo;
@end
static JPushPlugin *SharedJPushPlugin;
@interface NSDictionary (JPush)
-(NSString*)toJsonString;
@end
@interface NSString (JPush)
-(NSDictionary*)toDictionary;
@end

View File

@ -1,484 +1,318 @@
//
// PushTalkPlugin.m
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
//
//
#import "JPushPlugin.h"
#import "JPUSHService.h"
#import <UIKit/UIKit.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
#import "AppDelegate+JPush.h"
static NSString *const JP_APP_KEY = @"APP_KEY";
static NSString *const JP_APP_CHANNEL = @"CHANNEL";
static NSString *const JP_APP_ISPRODUCTION = @"IsProduction";
static NSString *const JP_APP_ISIDFA = @"IsIDFA";
static NSString *const JPushConfigFileName = @"PushConfig";
static NSDictionary *_launchOptions = nil;
#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
@implementation NSDictionary (JPush)
-(NSString*)toJsonString{
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:self options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
return jsonString;
}
@end
@implementation NSString (JPush)
-(NSDictionary*)toDictionary{
NSError *error;
NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
return dict;
}
@end
@interface JPushPlugin()
@end
@implementation JPushPlugin
#pragma mark-
-(void)stopPush:(CDVInvokedUrlCommand*)command{
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
}
-(void)resumePush:(CDVInvokedUrlCommand*)command{
[JPushPlugin registerForRemoteNotification];
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result;
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
result = @(0);
}else{
result = @(1);
}
[self handleResultWithValue:result command:command];
}
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
}
#ifdef __CORDOVA_4_0_0
- (void)pluginInitialize {
NSLog(@"### pluginInitialize ");
[self initNotifications];
}
#else
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
NSLog(@"### initWithWebView ");
if (self=[super initWithWebView:theWebView]) {
[self initNotifications];
}
return self;
}
#endif
-(void)initNotifications {
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginReceiveNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginiOS10ForegroundReceiveNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(networkDidReceiveNotification:)
name:kJPushPluginiOS10ClickNotification
object:nil];
if (_launchOptions) {
NSDictionary *userInfo = [_launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if ([userInfo count] >0) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",[userInfo toJsonString]]];
});
}
}
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments = command.arguments;
NSString *alias;
NSArray *tags;
if (!arguments || [arguments count] < 2) {
NSLog(@"#### setTagsWithAlias param is less");
return ;
}else{
alias = arguments[0];
tags = arguments[1];
}
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,tags);
[JPUSHService setTags:[NSSet setWithArray:tags]
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)setTags:(CDVInvokedUrlCommand *)command{
NSArray *tags = command.arguments;
NSLog(@"#### setTags %@",tags);
[JPUSHService setTags:[NSSet setWithArray:tags]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)setAlias:(CDVInvokedUrlCommand *)command{
NSLog(@"#### setAlias %@",command.arguments);
[JPUSHService setAlias:command.arguments[0]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registrationID = [JPUSHService registrationID];
NSLog(@"### getRegistrationID %@",registrationID);
[self handleResultWithValue:registrationID command:command];
}
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments = command.arguments;
if (!arguments || [arguments count] < 1) {
NSLog(@"startLogPageView argument error");
return ;
}
NSString * pageName = arguments[0];
if (pageName) {
[JPUSHService startLogPageView:pageName];
}
}
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments = command.arguments;
if (!arguments || [arguments count] < 1) {
NSLog(@"stopLogPageView argument error");
return ;
}
NSString * pageName = arguments[0];
if (pageName) {
[JPUSHService stopLogPageView:pageName];
}
}
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
NSArray *arguments = command.arguments;
if (!arguments || [arguments count] < 2) {
NSLog(@"beginLogPageView argument error");
return ;
}
NSString * pageName = arguments[0];
int duration = [arguments[0] intValue];
if (pageName) {
[JPUSHService beginLogPageView:pageName duration:duration];
}
}
-(void)setBadge:(CDVInvokedUrlCommand*)command{
NSArray *argument = command.arguments;
if ([argument count] < 1) {
NSLog(@"setBadge argument error!");
return;
}
NSNumber *badge = argument[0];
[JPUSHService setBadge:[badge intValue]];
}
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
[JPUSHService resetBadge];
}
-(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];
}
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
NSNumber *number = [NSNumber numberWithInteger:num];
[self handleResultWithValue:number command:command];
}
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
[JPUSHService setDebugMode];
}
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
[JPUSHService setLogOFF];
}
-(void)crashLogON:(CDVInvokedUrlCommand*)command{
[JPUSHService crashLogON];
}
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
NSArray *arguments = command.arguments;
NSDate *date = arguments[0] == [NSNull null] ? nil : [NSDate dateWithTimeIntervalSinceNow:[((NSString*)arguments[0]) intValue]];
NSString *alertBody = arguments[1] == [NSNull null] ? nil : (NSString*)arguments[1];
int badge = arguments[2] == [NSNull null] ? 0 : [(NSString*)arguments[2] intValue];
NSString *idKey = arguments[3] == [NSNull null] ? nil : (NSString*)arguments[3];
NSDictionary *dict = arguments[4] == [NSNull null] ? nil : (NSDictionary*)arguments[4];
[JPUSHService setLocalNotification:date alertBody:alertBody badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
}
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
NSString *identifier = [command argumentAtIndex:0];
if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) {
JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
jpid.identifiers = @[identifier];
[JPUSHService removeNotification:jpid];
}else{
[JPUSHService deleteLocalNotificationWithIdentifierKey:identifier];
}
}
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
[JPUSHService clearAllLocalNotifications];
}
-(void)setLocation:(CDVInvokedUrlCommand*)command{
[JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
}
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
WEAK_SELF(weakSelf);
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[@"authorizationStatus"] = @(settings.authorizationStatus);
dict[@"soundSetting"] = @(settings.soundSetting);
dict[@"badgeSetting"] = @(settings.badgeSetting);
dict[@"alertSetting"] = @(settings.alertSetting);
dict[@"notificationCenterSetting"] = @(settings.notificationCenterSetting);
dict[@"lockScreenSetting"] = @(settings.lockScreenSetting);
dict[@"carPlaySetting"] = @(settings.carPlaySetting);
dict[@"alertStyle"] = @(settings.alertStyle);
[weakSelf handleResultWithValue:dict command:command];
}];
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
UIUserNotificationType type = settings.types;
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}else{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}
}
#pragma mark - ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command{
[self addActions:command dismiss:YES];
}
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command{
[self addActions:command dismiss:NO];
}
-(void)addActions:(CDVInvokedUrlCommand*)command dismiss:(BOOL)dimiss{
NSArray *actionsData = [command argumentAtIndex:0];
NSString *categoryId = [command argumentAtIndex:1];
NSMutableArray *actions = [NSMutableArray array];
for (NSDictionary *dict in actionsData) {
NSString *title = dict[@"title"];
NSString *identifier = dict[@"identifier"];
NSString *option = dict[@"option"];
NSString *type = dict[@"type"];
if ([type isEqualToString:@"textInput"]) {
NSString *textInputButtonTitle = dict[@"textInputButtonTitle"];
NSString *textInputPlaceholder = dict[@"textInputPlaceholder"];
UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:option.integerValue textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder];
[actions addObject:inputAction];
}else{
UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:title title:title options:option.integerValue];
[actions addObject:action];
}
}
UNNotificationCategory *category;
if (dimiss) {
category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
}else{
category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
}
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];
}
#pragma mark -
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_launchOptions = theLaunchOptions;
[JPUSHService setDebugMode];
[JPushPlugin registerForRemoteNotification];
//read appkey and channel from PushConfig.plist
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfigFileName ofType:@"plist"];
if (plistPath == nil) {
NSLog(@"error: PushConfig.plist not found");
assert(0);
}
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSString * appkey = [plistData valueForKey:JP_APP_KEY];
NSString * channel = [plistData valueForKey:JP_APP_CHANNEL];
NSNumber * isProduction = [plistData valueForKey:JP_APP_ISPRODUCTION];
NSNumber *isIDFA = [plistData valueForKey:JP_APP_ISIDFA];
NSString *advertisingId = nil;
if(isIDFA){
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
[JPUSHService setupWithOption:_launchOptions
appKey:appkey
channel:channel
apsForProduction:[isProduction boolValue]
advertisingIdentifier:advertisingId];
}
+(void)registerForRemoteNotification{
[(AppDelegate*)[UIApplication sharedApplication].delegate registerForIos10RemoteNotification];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
//categories
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
} else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
//categories nil
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)
categories:nil];
}
}
#pragma mark js
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
CDVPluginResult *result = nil;
CDVCommandStatus status = CDVCommandStatus_OK;
if ([value isKindOfClass:[NSString class]]) {
value = [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
} else if ([value isKindOfClass:[NSNull class]]) {
value = nil;
}
if ([value isKindOfClass:[NSObject class]]) {
result = [CDVPluginResult resultWithStatus:status messageAsString:value];//NSObject
} else {
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
result = nil;
}
if (!result) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
#pragma mark
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
NSDictionary *dict = @{@"resultCode":[NSNumber numberWithInt:resultCode],
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
@"alias" :alias == nil ? [NSNull null] : alias
};
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",[dict toJsonString]]];
});
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
if (notification) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",[notification.userInfo toJsonString]]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",[notification.userInfo toJsonString]]];
});
}
}
-(void)networkDidReceiveNotification:(NSNotification *)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:{
//
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
break;
}
case UIApplicationStateBackground:{
//
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.backgoundNotification',%@)",jsonString]];
});
break;
}
default:
//do nothing
break;
}
}
@end
//
// PushTalkPlugin.m
// PushTalk
//
// Created by pikacode@qq.com on 13-12-13.
//
//
#import "JPushPlugin.h"
#import "JPUSHService.h"
#import <UIKit/UIKit.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
#import "AppDelegate+JPush.h"
#import "JPushDefine.h"
@implementation NSDictionary (JPush)
-(NSString*)toJsonString{
NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:self options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
return jsonString;
}
@end
@implementation NSString (JPush)
-(NSDictionary*)toDictionary{
NSError *error;
NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
return dict;
}
@end
@interface JPushPlugin()
@end
@implementation JPushPlugin
#pragma mark-
-(void)stopPush:(CDVInvokedUrlCommand*)command{
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
}
-(void)resumePush:(CDVInvokedUrlCommand*)command{
[(AppDelegate*)[UIApplication sharedApplication].delegate registerForRemoteNotification];
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] ? @(0) : @(1);
[self handleResultWithValue:result command:command];
}
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
}
#ifdef __CORDOVA_4_0_0
- (void)pluginInitialize {
NSLog(@"### pluginInitialize ");
SharedJPushPlugin = self;
}
#else
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
NSLog(@"### initWithWebView ");
if (self=[super initWithWebView:theWebView]) {
}
return self;
}
#endif
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
});
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSString *alias = [command argumentAtIndex:0];
NSArray *tags = [command argumentAtIndex:1];
[JPUSHService setTags:[NSSet setWithArray:tags]
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)setTags:(CDVInvokedUrlCommand *)command{
NSArray *tags = command.arguments;
[JPUSHService setTags:[NSSet setWithArray:tags]
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)setAlias:(CDVInvokedUrlCommand *)command{
NSString *alias = [command argumentAtIndex:0];
[JPUSHService setAlias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
object:self];
}
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
NSString* registrationID = [JPUSHService registrationID];
[self handleResultWithValue:registrationID command:command];
}
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
NSString * pageName = [command argumentAtIndex:0];
[JPUSHService startLogPageView:pageName];
}
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
NSString * pageName = [command argumentAtIndex:0];
[JPUSHService stopLogPageView:pageName];
}
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
NSString *pageName = [command argumentAtIndex:0];
NSNumber *duration = [command argumentAtIndex:1];
[JPUSHService beginLogPageView:pageName duration:duration.intValue];
}
-(void)setBadge:(CDVInvokedUrlCommand*)command{
NSNumber *badge = [command argumentAtIndex:0];
[JPUSHService setBadge:badge.intValue];
}
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
[JPUSHService resetBadge];
}
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
NSNumber *badge = [command argumentAtIndex:0];
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
}
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
NSNumber *number = [NSNumber numberWithInteger:num];
[self handleResultWithValue:number command:command];
}
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
[JPUSHService setDebugMode];
}
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
[JPUSHService setLogOFF];
}
-(void)crashLogON:(CDVInvokedUrlCommand*)command{
[JPUSHService crashLogON];
}
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
NSLog(@"ios 10 after please use UNNotificationRequest to set local notification, see apple doc to learn more");
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
NSString *alert = [command argumentAtIndex:1];
NSNumber *badge = [command argumentAtIndex:2];
NSString *idKey = [command argumentAtIndex:3];
NSDictionary *dict = [command argumentAtIndex:4];
[JPUSHService setLocalNotification:date alertBody:alert badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
}
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
NSString *identifier = [command argumentAtIndex:0];
JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
jpid.identifiers = @[identifier];
[JPUSHService removeNotification:jpid];
}
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
[JPUSHService removeNotification:nil];
}
-(void)setLocation:(CDVInvokedUrlCommand*)command{
NSNumber *latitude = [command argumentAtIndex:0];
NSNumber *longitude = [command argumentAtIndex:1];
[JPUSHService setLatitude:latitude.doubleValue longitude:longitude.doubleValue];
}
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
WEAK_SELF(weakSelf);
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[@"authorizationStatus"] = @(settings.authorizationStatus);
dict[@"soundSetting"] = @(settings.soundSetting);
dict[@"badgeSetting"] = @(settings.badgeSetting);
dict[@"alertSetting"] = @(settings.alertSetting);
dict[@"notificationCenterSetting"] = @(settings.notificationCenterSetting);
dict[@"lockScreenSetting"] = @(settings.lockScreenSetting);
dict[@"carPlaySetting"] = @(settings.carPlaySetting);
dict[@"alertStyle"] = @(settings.alertStyle);
[weakSelf handleResultWithValue:dict command:command];
}];
}else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
UIUserNotificationType type = settings.types;
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}else{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
NSNumber *number = [NSNumber numberWithInteger:type];
[self handleResultWithValue:number command:command];
}
}
#pragma mark - ios 10 APIs
-(void)addDismissActions:(CDVInvokedUrlCommand*)command{
[self addActions:command dismiss:YES];
}
-(void)addNotificationActions:(CDVInvokedUrlCommand*)command{
[self addActions:command dismiss:NO];
}
-(void)addActions:(CDVInvokedUrlCommand*)command dismiss:(BOOL)dimiss{
NSArray *actionsData = [command argumentAtIndex:0];
NSString *categoryId = [command argumentAtIndex:1];
NSMutableArray *actions = [NSMutableArray array];
for (NSDictionary *dict in actionsData) {
NSString *title = dict[@"title"];
NSString *identifier = dict[@"identifier"];
NSString *option = dict[@"option"];
NSString *type = dict[@"type"];
if ([type isEqualToString:@"textInput"]) {
NSString *textInputButtonTitle = dict[@"textInputButtonTitle"];
NSString *textInputPlaceholder = dict[@"textInputPlaceholder"];
UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:option.integerValue textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder];
[actions addObject:inputAction];
}else{
UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:title title:title options:option.integerValue];
[actions addObject:action];
}
}
UNNotificationCategory *category;
if (dimiss) {
category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
}else{
category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
}
[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];
}
#pragma mark -
+(void)setupJPushSDK:(NSDictionary*)userInfo{
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
if (plistPath == nil) {
NSLog(@"error: PushConfig.plist not found");
assert(0);
}
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSString *appkey = [plistData valueForKey:JPushConfig_Appkey];
NSString *channel = [plistData valueForKey:JPushConfig_Channel];
NSNumber *isProduction = [plistData valueForKey:JPushConfig_IsProduction];
NSNumber *isIDFA = [plistData valueForKey:JPushConfig_IsIDFA];
NSString *advertisingId = nil;
if(isIDFA){
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
[JPUSHService setupWithOption:userInfo
appKey:appkey
channel:channel
apsForProduction:[isProduction boolValue]
advertisingIdentifier:advertisingId];
}
#pragma mark js
-(void)handleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
CDVPluginResult *result = nil;
CDVCommandStatus status = CDVCommandStatus_OK;
if ([value isKindOfClass:[NSString class]]) {
value = [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
} else if ([value isKindOfClass:[NSNull class]]) {
value = nil;
}
if ([value isKindOfClass:[NSObject class]]) {
result = [CDVPluginResult resultWithStatus:status messageAsString:value];//NSObject
} else {
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
result = nil;
}
if (!result) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
#pragma mark
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
NSDictionary *dict = @{@"resultCode":[NSNumber numberWithInt:resultCode],
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
@"alias" :alias == nil ? [NSNull null] : alias
};
[self jpushFireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[dict toJsonString]];
}
- (void)networkDidReceiveMessage:(NSNotification *)notification {
if (notification && notification.userInfo) {
[self jpushFireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]];
}
}
@end

View File

@ -2,9 +2,9 @@
<!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>
<key>Appkey</key>
<string></string>
<key>CHANNEL</key>
<key>Channel</key>
<string>Subscription</string>
<key>IsProduction</key>
<false/>

View File

@ -9,7 +9,7 @@
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
*/
#define JPUSH_VERSION_NUMBER 2.1.9
#define JPUSH_VERSION_NUMBER 2.2.0
#import <Foundation/Foundation.h>

View File

@ -165,17 +165,6 @@ JPushPlugin.prototype.setLocation = function (latitude, longitude) {
}
}
JPushPlugin.prototype.receiveMessageIniOSCallback = function (data) {
try {
console.log('JPushPlugin:receiveMessageIniOSCallback--data:' + data)
var bToObj = JSON.parse(data)
var content = bToObj.content
console.log(content)
} catch(exception) {
console.log('JPushPlugin:receiveMessageIniOSCallback' + exception)
}
}
JPushPlugin.prototype.startLogPageView = function (pageName) {
if (this.isPlatformIOS()) {
this.call_native('startLogPageView', [pageName], null)