2014-01-20 18:27:31 +08:00
|
|
|
//
|
|
|
|
// PushTalkPlugin.m
|
|
|
|
// PushTalk
|
|
|
|
//
|
|
|
|
// Created by zhangqinghe on 13-12-13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "JPushPlugin.h"
|
2016-01-21 15:15:48 +08:00
|
|
|
#import "JPUSHService.h"
|
2015-04-10 11:04:56 +08:00
|
|
|
#import <UIKit/UIKit.h>
|
2014-01-20 18:27:31 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
static NSString *const JM_APP_KEY = @"APP_KEY";
|
|
|
|
static NSString *const JM_APP_CHANNEL = @"CHANNEL";
|
|
|
|
static NSString *const JM_APP_ISPRODUCTION = @"IsProduction";
|
|
|
|
|
|
|
|
static NSString *const JMessageConfigFileName = @"PushConfig";
|
|
|
|
|
|
|
|
|
2015-04-10 13:42:25 +08:00
|
|
|
static NSDictionary *_luanchOptions=nil;
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
@implementation JPushPlugin
|
2014-06-05 16:36:54 +08:00
|
|
|
|
2015-04-10 13:42:25 +08:00
|
|
|
|
|
|
|
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
2016-01-21 15:15:48 +08:00
|
|
|
_luanchOptions=theLaunchOptions;
|
|
|
|
[JPUSHService setDebugMode];
|
|
|
|
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
|
|
|
//可以添加自定义categories
|
|
|
|
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
|
|
|
UIUserNotificationTypeSound |
|
|
|
|
UIUserNotificationTypeAlert)
|
|
|
|
categories:nil];
|
|
|
|
} else {
|
|
|
|
//categories 必须为nil
|
|
|
|
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
|
|
|
UIRemoteNotificationTypeSound |
|
|
|
|
UIRemoteNotificationTypeAlert)
|
|
|
|
categories:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
//read appkey and channel from JMessageConfig.plist
|
|
|
|
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JMessageConfigFileName ofType:@"plist"];
|
|
|
|
if (plistPath == nil) {
|
|
|
|
NSLog(@"error: PushConfig.plist not found");
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
|
|
|
NSString * appkey = [plistData valueForKey:JM_APP_KEY];
|
|
|
|
NSString * channel = [plistData valueForKey:JM_APP_CHANNEL];
|
|
|
|
NSNumber * isProduction = [plistData valueForKey:JM_APP_ISPRODUCTION];
|
|
|
|
|
|
|
|
if (!appkey || appkey.length == 0) {
|
|
|
|
NSLog(@"error: app key not found in JMessageConfig.plist ");
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
[JPUSHService setupWithOption:_luanchOptions appKey:appkey
|
|
|
|
channel:channel apsForProduction:[isProduction boolValue] ];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)stopPush:(CDVInvokedUrlCommand*)command{
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)resumePush:(CDVInvokedUrlCommand*)command{
|
|
|
|
|
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
|
|
|
|
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
|
|
|
//可以添加自定义categories
|
|
|
|
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
|
|
|
UIUserNotificationTypeSound |
|
|
|
|
UIUserNotificationTypeAlert)
|
|
|
|
categories:nil];
|
|
|
|
} else {
|
|
|
|
//categories 必须为nil
|
|
|
|
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
|
|
|
UIRemoteNotificationTypeSound |
|
|
|
|
UIRemoteNotificationTypeAlert)
|
|
|
|
categories:nil];
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
//categories 必须为nil
|
|
|
|
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
|
|
|
UIRemoteNotificationTypeSound |
|
|
|
|
UIRemoteNotificationTypeAlert)
|
|
|
|
categories:nil];
|
|
|
|
#endif
|
|
|
|
|
2015-04-10 13:42:25 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
|
|
|
|
|
|
|
NSNumber *result;
|
|
|
|
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
|
|
|
|
result=@(0);
|
|
|
|
}else{
|
|
|
|
result=@(1);
|
|
|
|
}
|
|
|
|
CDVPluginResult * pushResult=[self pluginResultForValue:result];
|
|
|
|
if (pushResult) {
|
|
|
|
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
|
|
|
|
} else {
|
|
|
|
[self failWithCallbackID:command.callbackId];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-14 10:05:14 +08:00
|
|
|
-(void)initial:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
//do nithng,because Cordova plugin use lazy load mode.
|
2015-04-14 10:05:14 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __CORDOVA_4_0_0
|
|
|
|
|
|
|
|
- (void)pluginInitialize {
|
|
|
|
NSLog(@"### pluginInitialize ");
|
|
|
|
[self initNotifications];
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2014-07-22 18:51:48 +08:00
|
|
|
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
2016-01-21 15:15:48 +08:00
|
|
|
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];
|
|
|
|
|
|
|
|
if (_luanchOptions) {
|
|
|
|
NSDictionary *userInfo = [_luanchOptions
|
|
|
|
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
|
|
|
if ([userInfo count] >0) {
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
|
|
|
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
if (!error) {
|
2015-03-10 16:46:44 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
|
|
|
});
|
2015-04-14 09:58:44 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
}
|
2014-07-22 18:51:48 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
}
|
2014-07-22 18:51:48 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
NSArray *arguments=command.arguments;
|
|
|
|
if (!arguments||[arguments count]<2) {
|
2014-01-20 18:27:31 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
NSLog(@"#### setTagsWithAlias param is less");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
NSString *alias=[arguments objectAtIndex:0];
|
|
|
|
NSArray *arrayTags=[arguments objectAtIndex:1];
|
|
|
|
|
|
|
|
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,arrayTags);
|
|
|
|
|
|
|
|
NSSet* set=[NSSet setWithArray:arrayTags];
|
|
|
|
[JPUSHService setTags:set
|
|
|
|
alias:alias
|
|
|
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
|
|
|
object:self];
|
2014-01-20 18:27:31 +08:00
|
|
|
}
|
2015-03-30 10:28:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
|
|
|
|
|
|
|
|
|
|
|
NSArray *arguments=[command arguments];
|
|
|
|
NSString *tags=[arguments objectAtIndex:0];
|
|
|
|
|
|
|
|
NSLog(@"#### setTags %@",tags);
|
|
|
|
|
|
|
|
NSArray *array=[tags componentsSeparatedByString:@","];
|
|
|
|
[JPUSHService setTags:[NSSet setWithArray:array]
|
|
|
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
|
|
|
object:self];
|
|
|
|
|
2015-03-30 10:28:01 +08:00
|
|
|
}
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
NSArray *arguments=[command arguments];
|
|
|
|
NSLog(@"#### setAlias %@",arguments);
|
|
|
|
[JPUSHService setAlias:[arguments objectAtIndex:0]
|
|
|
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
|
|
|
object:self];
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
}
|
2014-06-05 16:36:54 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
2014-06-05 16:36:54 +08:00
|
|
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
NSString* registrationID = [JPUSHService registrationID];
|
|
|
|
NSLog(@"### getRegistrationID %@",registrationID);
|
|
|
|
|
|
|
|
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
|
|
|
if (result) {
|
|
|
|
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
|
|
|
} else {
|
|
|
|
[self failWithCallbackID:command.callbackId];
|
|
|
|
}
|
2014-06-05 16:36:54 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithInt:resultCode],@"resultCode",
|
|
|
|
tags==nil?[NSNull null]:[tags allObjects],@"tags",
|
|
|
|
alias==nil?[NSNull null]:alias,@"alias",nil];
|
|
|
|
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
|
|
|
[data setObject:[NSNumber numberWithInt:resultCode] forKey:@"resultCode"];
|
|
|
|
[data setObject:tags==nil?[NSNull null]:[tags allObjects] forKey:@"tags"];
|
|
|
|
[data setObject:alias==nil?[NSNull null]:alias forKey:@"alias"];
|
|
|
|
NSError *error;
|
|
|
|
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
|
|
|
|
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
|
|
|
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
|
|
|
});
|
|
|
|
|
2014-06-05 16:36:54 +08:00
|
|
|
}
|
2014-06-10 14:14:02 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
2014-06-05 16:36:54 +08:00
|
|
|
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
NSArray *arguments=command.arguments;
|
|
|
|
if (!arguments||[arguments count]<1) {
|
|
|
|
NSLog(@"startLogPageView argument error");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
NSString * pageName=[arguments objectAtIndex:0];
|
|
|
|
if (pageName) {
|
|
|
|
[JPUSHService startLogPageView:pageName];
|
|
|
|
}
|
2014-06-05 16:36:54 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
|
|
|
NSArray *arguments=command.arguments;
|
|
|
|
if (!arguments||[arguments count]<1) {
|
|
|
|
NSLog(@"stopLogPageView argument error");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
NSString * pageName=[arguments objectAtIndex:0];
|
|
|
|
if (pageName) {
|
|
|
|
[JPUSHService stopLogPageView:pageName];
|
|
|
|
}
|
|
|
|
|
2015-01-16 10:42:06 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
|
|
|
NSArray *arguments=command.arguments;
|
|
|
|
if (!arguments||[arguments count]<2) {
|
|
|
|
NSLog(@"beginLogPageView argument error");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
NSString * pageName=[arguments objectAtIndex:0];
|
|
|
|
int duration=[[arguments objectAtIndex:0]intValue];
|
|
|
|
if (pageName) {
|
|
|
|
[JPUSHService beginLogPageView:pageName duration:duration];
|
|
|
|
}
|
|
|
|
|
2014-06-04 13:20:24 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
2014-09-24 20:02:07 +08:00
|
|
|
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
NSArray *argument=command.arguments;
|
|
|
|
if ([argument count]<1) {
|
|
|
|
NSLog(@"setBadge argument error!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSNumber *badge=[argument objectAtIndex:0];
|
|
|
|
[JPUSHService setBadge:[badge intValue]];
|
2014-09-24 20:02:07 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-24 20:02:07 +08:00
|
|
|
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
[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];
|
2014-09-24 20:02:07 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
|
|
|
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
|
|
|
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:num];
|
|
|
|
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-24 20:02:07 +08:00
|
|
|
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
[JPUSHService setDebugMode];
|
2014-09-24 20:02:07 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-24 20:02:07 +08:00
|
|
|
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
[JPUSHService setLogOFF];
|
2014-09-24 20:02:07 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
2014-06-10 14:14:02 +08:00
|
|
|
- (void)failWithCallbackID:(NSString *)callbackID {
|
2016-01-21 15:15:48 +08:00
|
|
|
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
|
|
|
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
2014-06-10 14:14:02 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-10 14:14:02 +08:00
|
|
|
- (void)succeedWithPluginResult:(CDVPluginResult *)result withCallbackID:(NSString *)callbackID {
|
2016-01-21 15:15:48 +08:00
|
|
|
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
2015-03-25 16:11:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
2014-06-10 14:14:02 +08:00
|
|
|
- (CDVPluginResult *)pluginResultForValue:(id)value {
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
CDVPluginResult *result;
|
|
|
|
if ([value isKindOfClass:[NSString class]]) {
|
|
|
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
|
|
messageAsString:[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
|
|
|
} else if ([value isKindOfClass:[NSNumber class]]) {
|
|
|
|
CFNumberType numberType = CFNumberGetType((CFNumberRef)value);
|
|
|
|
//note: underlyingly, BOOL values are typedefed as char
|
|
|
|
if (numberType == kCFNumberIntType || numberType == kCFNumberCharType) {
|
|
|
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[value intValue]];
|
|
|
|
} else {
|
|
|
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[value doubleValue]];
|
2014-06-10 14:14:02 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
} else if ([value isKindOfClass:[NSArray class]]) {
|
|
|
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:value];
|
|
|
|
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
|
|
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:value];
|
|
|
|
} else if ([value isKindOfClass:[NSNull class]]) {
|
|
|
|
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
|
|
} else {
|
|
|
|
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return result;
|
2014-06-10 14:14:02 +08:00
|
|
|
}
|
|
|
|
|
2014-07-22 18:51:48 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
|
|
|
|
|
|
|
NSDictionary *userInfo = [notification userInfo];
|
|
|
|
//NSLog(@"%@",userInfo);
|
|
|
|
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
|
|
|
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
//NSLog(@"%@",jsonString);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2014-07-22 18:51:48 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
|
2014-07-22 18:51:48 +08:00
|
|
|
|
2016-01-21 15:15:48 +08:00
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2015-04-14 14:47:57 +08:00
|
|
|
|
2014-07-22 18:51:48 +08:00
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
|
2015-03-10 16:46:44 +08:00
|
|
|
-(void)networkDidReceiveNotification:(id)notification{
|
2016-01-21 15:15:48 +08:00
|
|
|
|
|
|
|
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]];
|
|
|
|
});
|
2015-04-10 11:04:56 +08:00
|
|
|
}
|
2016-01-21 15:15:48 +08:00
|
|
|
break;
|
|
|
|
case UIApplicationStateInactive:
|
|
|
|
case UIApplicationStateBackground:
|
|
|
|
{
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-10 16:46:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
@end
|