mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-05-03 08:32:57 +08:00
iOS - update
1.更新 SDK 2.删除过期方法 3.更新过期方法 4.删除重复方法 5.发现并修复 bug 6.优化代码 7.更新 doc
This commit is contained in:
parent
1cbd1b6e9d
commit
6d0dce371e
@ -53,8 +53,8 @@
|
|||||||
|
|
||||||
### iOS
|
### iOS
|
||||||
#### PushConfig.plist 文件中的字段都是什么意思?
|
#### PushConfig.plist 文件中的字段都是什么意思?
|
||||||
- APP_KEY:应用标识。
|
- Appkey:应用标识。
|
||||||
- CHANNEL:渠道标识。
|
- Channel:渠道标识。
|
||||||
- IsProduction:是否生产环境。
|
- IsProduction:是否生产环境。
|
||||||
- IsIDFA:是否使用 IDFA 启动 SDK。
|
- IsIDFA:是否使用 IDFA 启动 SDK。
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
|
|||||||
|
|
||||||
#### event - jpush.backgroundNotification
|
#### 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
|
"_j_msgid":154604475
|
||||||
}
|
}
|
||||||
|
|
||||||
#### API - receiveMessageIniOSCallback
|
|
||||||
|
|
||||||
用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
|
|
||||||
不推荐使用回调函数
|
|
||||||
|
|
||||||
##### 接口定义
|
|
||||||
|
|
||||||
JPushPlugin.prototype.receiveMessageIniOSCallback(data)
|
|
||||||
|
|
||||||
##### 参数说明
|
|
||||||
|
|
||||||
- data: 是一个 js 字符串使用如下代码解析,js 具体 key 根据应用内消息来确定:
|
|
||||||
|
|
||||||
var bToObj = JSON.parse(data);
|
|
||||||
|
|
||||||
|
|
||||||
## 获取自定义消息内容
|
## 获取自定义消息内容
|
||||||
|
@ -1,35 +1,39 @@
|
|||||||
## iOS 手动安装
|
## 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: 应用标识
|
Appkey: 应用标识
|
||||||
CHANNEL: 渠道标识
|
Channel: 渠道标识
|
||||||
IsProduction:是否生产环境
|
IsProduction:是否生产环境
|
||||||
IsIDFA: 是否使用 IDFA 启动 sdk
|
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
|
```xml
|
||||||
CoreFoundation.framework
|
<feature name="JPushPlugin">
|
||||||
CoreTelephony.framework
|
<param name="ios-package" value="JPushPlugin" />
|
||||||
SystemConfiguration.framework
|
<param name="onload" value="true" />
|
||||||
CoreGraphics.framework
|
</feature>
|
||||||
Foundation.framework
|
```
|
||||||
UIKit.framework
|
5. 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
|
||||||
AdSupport.framework
|
6. 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
|
||||||
libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
|
|
||||||
|
|
||||||
- 修改 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>
|
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
|
|
||||||
<header-file src="src/ios/Plugins/JPushPlugin.h" />
|
<header-file src="src/ios/Plugins/JPushPlugin.h" />
|
||||||
<source-file src="src/ios/Plugins/JPushPlugin.m" />
|
<source-file src="src/ios/Plugins/JPushPlugin.m" />
|
||||||
|
<header-file src="src/ios/Plugins/JPushDefine.h" />
|
||||||
<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/AppDelegate+JPush.h" />
|
<header-file src="src/ios/Plugins/AppDelegate+JPush.h" />
|
||||||
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
|
<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" />
|
<resource-file src="src/ios/PushConfig.plist" />
|
||||||
<framework src="CFNetwork.framework" weak="true" />
|
<framework src="CFNetwork.framework" weak="true" />
|
||||||
<framework src="CoreFoundation.framework" weak="true" />
|
<framework src="CoreFoundation.framework" weak="true" />
|
||||||
@ -49,9 +49,10 @@
|
|||||||
<framework src="libz.tbd" weak="true" />
|
<framework src="libz.tbd" weak="true" />
|
||||||
<framework src="AdSupport.framework" weak="true" />
|
<framework src="AdSupport.framework" weak="true" />
|
||||||
<framework src="UserNotifications.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>
|
<string>$API_KEY</string>
|
||||||
</config-file>
|
</config-file>
|
||||||
</platform>
|
</platform>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// AppDelegate+JPush.h
|
// AppDelegate+JPush.h
|
||||||
// delegateExtention
|
// delegateExtention
|
||||||
//
|
//
|
||||||
// Created by 张庆贺 on 15/8/3.
|
// Created by pikacode@qq.com on 15/8/3.
|
||||||
// Copyright (c) 2015年 JPush. All rights reserved.
|
// Copyright (c) 2015年 JPush. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -11,5 +11,5 @@
|
|||||||
#import "JPUSHService.h"
|
#import "JPUSHService.h"
|
||||||
|
|
||||||
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
|
@interface AppDelegate (JPush) <JPUSHRegisterDelegate>
|
||||||
-(void)registerForIos10RemoteNotification;
|
-(void)registerForRemoteNotification;
|
||||||
@end
|
@end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// AppDelegate+JPush.m
|
// AppDelegate+JPush.m
|
||||||
// delegateExtention
|
// delegateExtention
|
||||||
//
|
//
|
||||||
// Created by 张庆贺 on 15/8/3.
|
// Created by pikacode@qq.com on 15/8/3.
|
||||||
// Copyright (c) 2015年 JPush. All rights reserved.
|
// Copyright (c) 2015年 JPush. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -11,19 +11,16 @@
|
|||||||
#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"
|
||||||
|
|
||||||
|
|
||||||
@implementation AppDelegate (JPush)
|
@implementation AppDelegate (JPush)
|
||||||
|
|
||||||
+(void)load{
|
+(void)load{
|
||||||
|
Method origin1;
|
||||||
Method origin;
|
Method swizzle1;
|
||||||
Method swizzle;
|
origin1 = class_getInstanceMethod([self class],@selector(init));
|
||||||
|
swizzle1 = class_getInstanceMethod([self class], @selector(init_plus));
|
||||||
origin=class_getInstanceMethod([self class],@selector(init));
|
method_exchangeImplementations(origin1, swizzle1);
|
||||||
swizzle=class_getInstanceMethod([self class], @selector(init_plus));
|
|
||||||
method_exchangeImplementations(origin, swizzle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(instancetype)init_plus{
|
-(instancetype)init_plus{
|
||||||
@ -31,10 +28,45 @@
|
|||||||
return [self init_plus];
|
return [self init_plus];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-(void)applicationDidLaunch:(NSNotification *)notification{
|
-(void)applicationDidLaunch:(NSNotification *)notification{
|
||||||
if (notification) {
|
if (notification) {
|
||||||
[self registerForIos10RemoteNotification];
|
if (notification.userInfo) {
|
||||||
[JPushPlugin setLaunchOptions: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{
|
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
||||||
[JPUSHService handleRemoteNotification: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{
|
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
|
||||||
[JPUSHService handleRemoteNotification:userInfo];
|
[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);
|
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 {
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||||
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
|
// [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveLocalNotification object:notification.userInfo];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
@ -66,36 +129,4 @@
|
|||||||
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
// [[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
|
@end
|
||||||
|
31
src/ios/Plugins/JPushDefine.h
Normal file
31
src/ios/Plugins/JPushDefine.h
Normal 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";
|
||||||
|
|
||||||
|
|
@ -2,23 +2,16 @@
|
|||||||
// PushTalkPlugin.h
|
// PushTalkPlugin.h
|
||||||
// PushTalk
|
// PushTalk
|
||||||
//
|
//
|
||||||
// Created by zhangqinghe on 13-12-13.
|
// Created by pikacode@qq.com on 13-12-13.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Cordova/CDV.h>
|
#import <Cordova/CDV.h>
|
||||||
|
|
||||||
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
|
|
||||||
#define kJPushPluginiOS10ForegroundReceiveNotification @"kJPushPluginiOS10ForegroundReceiveNotification"
|
|
||||||
#define kJPushPluginiOS10ClickNotification @"kJPushPluginiOS10ClickNotification"
|
|
||||||
|
|
||||||
|
|
||||||
@interface JPushPlugin : CDVPlugin{
|
@interface JPushPlugin : CDVPlugin{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions;
|
|
||||||
|
|
||||||
//以下为js中可调用接口
|
//以下为js中可调用接口
|
||||||
//设置标签、别名
|
//设置标签、别名
|
||||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
|
||||||
@ -77,4 +70,22 @@
|
|||||||
* jpush.backgroundNotification 后台收到推送
|
* jpush.backgroundNotification 后台收到推送
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
# pragma mark - private
|
||||||
|
|
||||||
|
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
|
||||||
|
|
||||||
|
+(void)setupJPushSDK:(NSDictionary*)userInfo;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static JPushPlugin *SharedJPushPlugin;
|
||||||
|
|
||||||
|
@interface NSDictionary (JPush)
|
||||||
|
-(NSString*)toJsonString;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSString (JPush)
|
||||||
|
-(NSDictionary*)toDictionary;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// PushTalkPlugin.m
|
// PushTalkPlugin.m
|
||||||
// PushTalk
|
// 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 <AdSupport/AdSupport.h>
|
||||||
#import <UserNotifications/UserNotifications.h>
|
#import <UserNotifications/UserNotifications.h>
|
||||||
#import "AppDelegate+JPush.h"
|
#import "AppDelegate+JPush.h"
|
||||||
|
#import "JPushDefine.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)
|
@implementation NSDictionary (JPush)
|
||||||
-(NSString*)toJsonString{
|
-(NSString*)toJsonString{
|
||||||
@ -52,16 +44,11 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)resumePush:(CDVInvokedUrlCommand*)command{
|
-(void)resumePush:(CDVInvokedUrlCommand*)command{
|
||||||
[JPushPlugin registerForRemoteNotification];
|
[(AppDelegate*)[UIApplication sharedApplication].delegate registerForRemoteNotification];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
||||||
NSNumber *result;
|
NSNumber *result = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] ? @(0) : @(1);
|
||||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
|
|
||||||
result = @(0);
|
|
||||||
}else{
|
|
||||||
result = @(1);
|
|
||||||
}
|
|
||||||
[self handleResultWithValue:result command:command];
|
[self handleResultWithValue:result command:command];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +56,11 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
//do nithng,because Cordova plugin use lazy load mode.
|
//do nithng,because Cordova plugin use lazy load mode.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __CORDOVA_4_0_0
|
#ifdef __CORDOVA_4_0_0
|
||||||
|
|
||||||
- (void)pluginInitialize {
|
- (void)pluginInitialize {
|
||||||
NSLog(@"### pluginInitialize ");
|
NSLog(@"### pluginInitialize ");
|
||||||
[self initNotifications];
|
SharedJPushPlugin = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -82,62 +68,21 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
||||||
NSLog(@"### initWithWebView ");
|
NSLog(@"### initWithWebView ");
|
||||||
if (self=[super initWithWebView:theWebView]) {
|
if (self=[super initWithWebView:theWebView]) {
|
||||||
[self initNotifications];
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
-(void)initNotifications {
|
-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
|
||||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[defaultCenter addObserver:self
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
|
||||||
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{
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *arguments = command.arguments;
|
NSString *alias = [command argumentAtIndex:0];
|
||||||
NSString *alias;
|
NSArray *tags = [command argumentAtIndex:1];
|
||||||
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]
|
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||||
alias:alias
|
alias:alias
|
||||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||||
@ -145,77 +90,43 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
||||||
|
|
||||||
NSArray *tags = command.arguments;
|
NSArray *tags = command.arguments;
|
||||||
|
|
||||||
NSLog(@"#### setTags %@",tags);
|
|
||||||
|
|
||||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||||
object:self];
|
object:self];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
||||||
|
NSString *alias = [command argumentAtIndex:0];
|
||||||
NSLog(@"#### setAlias %@",command.arguments);
|
[JPUSHService setAlias:alias
|
||||||
[JPUSHService setAlias:command.arguments[0]
|
|
||||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||||
object:self];
|
object:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||||
NSString* registrationID = [JPUSHService registrationID];
|
NSString* registrationID = [JPUSHService registrationID];
|
||||||
NSLog(@"### getRegistrationID %@",registrationID);
|
|
||||||
[self handleResultWithValue:registrationID command:command];
|
[self handleResultWithValue:registrationID command:command];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *arguments = command.arguments;
|
NSString * pageName = [command argumentAtIndex:0];
|
||||||
if (!arguments || [arguments count] < 1) {
|
[JPUSHService startLogPageView:pageName];
|
||||||
NSLog(@"startLogPageView argument error");
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
NSString * pageName = arguments[0];
|
|
||||||
if (pageName) {
|
|
||||||
[JPUSHService startLogPageView:pageName];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *arguments = command.arguments;
|
NSString * pageName = [command argumentAtIndex:0];
|
||||||
if (!arguments || [arguments count] < 1) {
|
[JPUSHService stopLogPageView:pageName];
|
||||||
NSLog(@"stopLogPageView argument error");
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
NSString * pageName = arguments[0];
|
|
||||||
if (pageName) {
|
|
||||||
[JPUSHService stopLogPageView:pageName];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *arguments = command.arguments;
|
NSString *pageName = [command argumentAtIndex:0];
|
||||||
if (!arguments || [arguments count] < 2) {
|
NSNumber *duration = [command argumentAtIndex:1];
|
||||||
NSLog(@"beginLogPageView argument error");
|
[JPUSHService beginLogPageView:pageName duration:duration.intValue];
|
||||||
return ;
|
|
||||||
}
|
|
||||||
NSString * pageName = arguments[0];
|
|
||||||
int duration = [arguments[0] intValue];
|
|
||||||
if (pageName) {
|
|
||||||
[JPUSHService beginLogPageView:pageName duration:duration];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *argument = command.arguments;
|
NSNumber *badge = [command argumentAtIndex:0];
|
||||||
if ([argument count] < 1) {
|
[JPUSHService setBadge:badge.intValue];
|
||||||
NSLog(@"setBadge argument error!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NSNumber *badge = argument[0];
|
|
||||||
[JPUSHService setBadge:[badge intValue]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
||||||
@ -223,14 +134,8 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
|
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
|
||||||
//
|
NSNumber *badge = [command argumentAtIndex:0];
|
||||||
NSArray *argument = command.arguments;
|
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
|
||||||
if ([argument count] < 1) {
|
|
||||||
NSLog(@"setBadge argument error!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NSNumber *badge = [argument objectAtIndex:0];
|
|
||||||
[UIApplication sharedApplication].applicationIconBadgeNumber = [badge intValue];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
||||||
@ -252,32 +157,31 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
||||||
NSArray *arguments = command.arguments;
|
NSLog(@"ios 10 after please use UNNotificationRequest to set local notification, see apple doc to learn more");
|
||||||
NSDate *date = arguments[0] == [NSNull null] ? nil : [NSDate dateWithTimeIntervalSinceNow:[((NSString*)arguments[0]) intValue]];
|
|
||||||
NSString *alertBody = arguments[1] == [NSNull null] ? nil : (NSString*)arguments[1];
|
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
|
||||||
int badge = arguments[2] == [NSNull null] ? 0 : [(NSString*)arguments[2] intValue];
|
NSString *alert = [command argumentAtIndex:1];
|
||||||
NSString *idKey = arguments[3] == [NSNull null] ? nil : (NSString*)arguments[3];
|
NSNumber *badge = [command argumentAtIndex:2];
|
||||||
NSDictionary *dict = arguments[4] == [NSNull null] ? nil : (NSDictionary*)arguments[4];
|
NSString *idKey = [command argumentAtIndex:3];
|
||||||
[JPUSHService setLocalNotification:date alertBody:alertBody badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
|
NSDictionary *dict = [command argumentAtIndex:4];
|
||||||
|
[JPUSHService setLocalNotification:date alertBody:alert badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
||||||
NSString *identifier = [command argumentAtIndex:0];
|
NSString *identifier = [command argumentAtIndex:0];
|
||||||
if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) {
|
JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
|
||||||
JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
|
jpid.identifiers = @[identifier];
|
||||||
jpid.identifiers = @[identifier];
|
[JPUSHService removeNotification:jpid];
|
||||||
[JPUSHService removeNotification:jpid];
|
|
||||||
}else{
|
|
||||||
[JPUSHService deleteLocalNotificationWithIdentifierKey:identifier];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
|
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
|
||||||
[JPUSHService clearAllLocalNotifications];
|
[JPUSHService removeNotification:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setLocation:(CDVInvokedUrlCommand*)command{
|
-(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{
|
-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
|
||||||
@ -347,54 +251,29 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - 内部方法
|
#pragma mark - 内部方法
|
||||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
|
||||||
_launchOptions = theLaunchOptions;
|
|
||||||
|
|
||||||
[JPUSHService setDebugMode];
|
+(void)setupJPushSDK:(NSDictionary*)userInfo{
|
||||||
|
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
|
||||||
[JPushPlugin registerForRemoteNotification];
|
|
||||||
|
|
||||||
//read appkey and channel from PushConfig.plist
|
|
||||||
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfigFileName ofType:@"plist"];
|
|
||||||
if (plistPath == nil) {
|
if (plistPath == nil) {
|
||||||
NSLog(@"error: PushConfig.plist not found");
|
NSLog(@"error: PushConfig.plist not found");
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||||
NSString * appkey = [plistData valueForKey:JP_APP_KEY];
|
NSString *appkey = [plistData valueForKey:JPushConfig_Appkey];
|
||||||
NSString * channel = [plistData valueForKey:JP_APP_CHANNEL];
|
NSString *channel = [plistData valueForKey:JPushConfig_Channel];
|
||||||
NSNumber * isProduction = [plistData valueForKey:JP_APP_ISPRODUCTION];
|
NSNumber *isProduction = [plistData valueForKey:JPushConfig_IsProduction];
|
||||||
NSNumber *isIDFA = [plistData valueForKey:JP_APP_ISIDFA];
|
NSNumber *isIDFA = [plistData valueForKey:JPushConfig_IsIDFA];
|
||||||
|
|
||||||
NSString *advertisingId = nil;
|
NSString *advertisingId = nil;
|
||||||
if(isIDFA){
|
if(isIDFA){
|
||||||
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
|
||||||
}
|
}
|
||||||
[JPUSHService setupWithOption:_launchOptions
|
[JPUSHService setupWithOption:userInfo
|
||||||
appKey:appkey
|
appKey:appkey
|
||||||
channel:channel
|
channel:channel
|
||||||
apsForProduction:[isProduction boolValue]
|
apsForProduction:[isProduction boolValue]
|
||||||
advertisingIdentifier:advertisingId];
|
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
|
#pragma mark 将参数返回给js
|
||||||
@ -427,58 +306,13 @@ static NSDictionary *_launchOptions = nil;
|
|||||||
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
|
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
|
||||||
@"alias" :alias == nil ? [NSNull null] : alias
|
@"alias" :alias == nil ? [NSNull null] : alias
|
||||||
};
|
};
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
[self jpushFireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[dict toJsonString]];
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",[dict toJsonString]]];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
||||||
if (notification) {
|
if (notification && notification.userInfo) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
[self jpushFireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]];
|
||||||
|
|
||||||
[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
|
@end
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>APP_KEY</key>
|
<key>Appkey</key>
|
||||||
<string></string>
|
<string></string>
|
||||||
<key>CHANNEL</key>
|
<key>Channel</key>
|
||||||
<string>Subscription</string>
|
<string>Subscription</string>
|
||||||
<key>IsProduction</key>
|
<key>IsProduction</key>
|
||||||
<false/>
|
<false/>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
|
* 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>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
Binary file not shown.
@ -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) {
|
JPushPlugin.prototype.startLogPageView = function (pageName) {
|
||||||
if (this.isPlatformIOS()) {
|
if (this.isPlatformIOS()) {
|
||||||
this.call_native('startLogPageView', [pageName], null)
|
this.call_native('startLogPageView', [pageName], null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user