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,15 +1,15 @@
## 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 渠道标识
Appkey 应用标识
Channel 渠道标识
IsProduction是否生产环境
IsIDFA 是否使用 IDFA 启动 sdk
- 打开 xcode点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
3. 打开 xcode点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
CFNetwork.framework
CoreFoundation.framework
@ -20,16 +20,20 @@
UIKit.framework
AdSupport.framework
libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
UserNotifications.framework
libresolv.tbd
4. 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
- 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
```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) 文档说明调用相应接口
- 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
- 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
```xml
<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

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

View File

@ -2,7 +2,7 @@
// AppDelegate+JPush.m
// delegateExtention
//
// Created by on 15/8/3.
// Created by pikacode@qq.com on 15/8/3.
// Copyright (c) 2015 JPush. All rights reserved.
//
@ -11,19 +11,16 @@
#import <objc/runtime.h>
#import <AdSupport/AdSupport.h>
#import <UserNotifications/UserNotifications.h>
#import "JPushDefine.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);
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{
@ -31,10 +28,45 @@
return [self init_plus];
}
-(void)applicationDidLaunch:(NSNotification *)notification{
if (notification) {
[self registerForIos10RemoteNotification];
[JPushPlugin setLaunchOptions:notification.userInfo];
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];
}
}
@ -44,17 +76,48 @@
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
[JPUSHService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
[SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
[JPUSHService handleRemoteNotification:userInfo];
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object: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 {
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
// [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveLocalNotification object:notification.userInfo];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
@ -66,36 +129,4 @@
// [[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

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

@ -2,23 +2,16 @@
// PushTalkPlugin.h
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
// Created by pikacode@qq.com 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;
@ -77,4 +70,22 @@
* 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

@ -2,7 +2,7 @@
// PushTalkPlugin.m
// PushTalk
//
// Created by zhangqinghe on 13-12-13.
// Created by pikacode@qq.com on 13-12-13.
//
//
@ -12,15 +12,7 @@
#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;
#import "JPushDefine.h"
@implementation NSDictionary (JPush)
-(NSString*)toJsonString{
@ -52,16 +44,11 @@ static NSDictionary *_launchOptions = nil;
}
-(void)resumePush:(CDVInvokedUrlCommand*)command{
[JPushPlugin registerForRemoteNotification];
[(AppDelegate*)[UIApplication sharedApplication].delegate registerForRemoteNotification];
}
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
NSNumber *result;
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
result = @(0);
}else{
result = @(1);
}
NSNumber *result = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] ? @(0) : @(1);
[self handleResultWithValue:result command:command];
}
@ -69,12 +56,11 @@ static NSDictionary *_launchOptions = nil;
//do nithng,because Cordova plugin use lazy load mode.
}
#ifdef __CORDOVA_4_0_0
- (void)pluginInitialize {
NSLog(@"### pluginInitialize ");
[self initNotifications];
SharedJPushPlugin = self;
}
#else
@ -82,62 +68,21 @@ static NSDictionary *_launchOptions = nil;
- (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) {
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",[userInfo toJsonString]]];
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
});
}
}
}
-(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);
NSString *alias = [command argumentAtIndex:0];
NSArray *tags = [command argumentAtIndex:1];
[JPUSHService setTags:[NSSet setWithArray:tags]
alias:alias
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
@ -145,77 +90,43 @@ static NSDictionary *_launchOptions = nil;
}
-(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]
NSString *alias = [command argumentAtIndex:0];
[JPUSHService setAlias:alias
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) {
NSString * pageName = [command argumentAtIndex:0];
[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) {
NSString * pageName = [command argumentAtIndex:0];
[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];
}
NSString *pageName = [command argumentAtIndex:0];
NSNumber *duration = [command argumentAtIndex:1];
[JPUSHService beginLogPageView:pageName duration:duration.intValue];
}
-(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]];
NSNumber *badge = [command argumentAtIndex:0];
[JPUSHService setBadge:badge.intValue];
}
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
@ -223,14 +134,8 @@ static NSDictionary *_launchOptions = nil;
}
-(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];
NSNumber *badge = [command argumentAtIndex:0];
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
}
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
@ -252,32 +157,31 @@ static NSDictionary *_launchOptions = nil;
}
-(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];
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];
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];
[JPUSHService removeNotification:nil];
}
-(void)setLocation:(CDVInvokedUrlCommand*)command{
[JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
NSNumber *latitude = [command argumentAtIndex:0];
NSNumber *longitude = [command argumentAtIndex:1];
[JPUSHService setLatitude:latitude.doubleValue longitude:longitude.doubleValue];
}
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
@ -347,54 +251,29 @@ static NSDictionary *_launchOptions = nil;
}
#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"];
+(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: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 *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:_launchOptions
[JPUSHService setupWithOption:userInfo
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
@ -427,58 +306,13 @@ static NSDictionary *_launchOptions = nil;
@"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]]];
});
[self jpushFireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[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]]];
});
if (notification && notification.userInfo) {
[self jpushFireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[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

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)