2014-01-20 18:27:31 +08:00
|
|
|
//
|
|
|
|
// PushTalkPlugin.m
|
|
|
|
// PushTalk
|
|
|
|
//
|
|
|
|
// Created by zhangqinghe on 13-12-13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "JPushPlugin.h"
|
|
|
|
#import "APService.h"
|
|
|
|
|
|
|
|
@implementation JPushPlugin
|
2014-06-05 16:36:54 +08:00
|
|
|
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
|
|
|
|
|
|
|
NSArray *arguments=command.arguments;
|
|
|
|
if (!arguments||[arguments count]<2) {
|
|
|
|
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
|
|
|
return ;
|
|
|
|
}
|
2014-06-06 18:15:08 +08:00
|
|
|
NSString *alias=[arguments objectAtIndex:0];
|
|
|
|
NSArray *arrayTags=[arguments objectAtIndex:1];
|
2014-01-20 18:27:31 +08:00
|
|
|
// NSArray *tags=[arguments subarrayWithRange:range];
|
2014-06-06 18:15:08 +08:00
|
|
|
NSSet* set=[NSSet setWithArray:arrayTags];
|
|
|
|
[APService setTags:set
|
2014-01-20 18:27:31 +08:00
|
|
|
alias:alias
|
|
|
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
|
|
|
object:self];
|
|
|
|
//[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
|
|
|
|
|
|
|
//CDVPluginResult *pluginResult=nil;
|
|
|
|
|
|
|
|
NSArray *arguments=[command arguments];
|
|
|
|
NSString *tags=[arguments objectAtIndex:0];
|
|
|
|
|
|
|
|
NSArray *array=[tags componentsSeparatedByString:@","];
|
|
|
|
[APService setTags:[NSSet setWithArray:array]
|
|
|
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
|
|
|
object:self];
|
|
|
|
//[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
|
|
|
|
|
|
|
CDVPluginResult *pluginResult=nil;
|
|
|
|
|
|
|
|
NSArray *arguments=[command arguments];
|
|
|
|
[APService setAlias:[arguments objectAtIndex:0]
|
|
|
|
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
|
|
|
object:self];
|
|
|
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
|
|
|
|
|
|
}
|
2014-06-05 16:36:54 +08:00
|
|
|
|
|
|
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
|
|
|
NSString* registratonID = [APService registrionID];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
//
|
|
|
|
NSString *script=[NSString stringWithFormat:@"cordova.fireDocumentEvent('registrationID','[%@]')",registratonID];
|
|
|
|
[self.commandDelegate evalJs:script];
|
|
|
|
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.registrationCallback('%@')",registratonID]];
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
|
|
|
|
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
|
|
|
|
|
|
|
|
2014-06-05 16:36:54 +08:00
|
|
|
NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
|
2014-01-20 18:27:31 +08:00
|
|
|
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithInt:resultCode],@"resultCode",
|
|
|
|
tags==nil?[NSNull null]:[tags allObjects],@"resultTags",
|
|
|
|
alias==nil?[NSNull null]:alias,@"resultAlias",nil];
|
|
|
|
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(), ^{
|
2014-06-05 16:36:54 +08:00
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('setTagsWithAlias','[%@]')",jsonString]];
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
|
|
|
});
|
|
|
|
}
|
2014-06-05 16:36:54 +08:00
|
|
|
- (void)networkDidSetup:(NSNotification *)notification {
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidSetup')"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)networkDidClose:(NSNotification *)notification {
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidClose')"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)networkDidRegister:(NSNotification *)notification {
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidRegister')"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)networkDidLogin:(NSNotification *)notification {
|
|
|
|
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidLogin')"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command{
|
|
|
|
|
|
|
|
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
|
|
|
|
|
|
|
[defaultCenter addObserver:self
|
|
|
|
selector:@selector(networkDidSetup:)
|
|
|
|
name:kAPNetworkDidSetupNotification
|
|
|
|
object:nil];
|
|
|
|
[defaultCenter addObserver:self
|
|
|
|
selector:@selector(networkDidClose:)
|
|
|
|
name:kAPNetworkDidCloseNotification
|
|
|
|
object:nil];
|
|
|
|
[defaultCenter addObserver:self
|
|
|
|
selector:@selector(networkDidRegister:)
|
|
|
|
name:kAPNetworkDidRegisterNotification
|
|
|
|
object:nil];
|
|
|
|
[defaultCenter addObserver:self
|
|
|
|
selector:@selector(networkDidLogin:)
|
|
|
|
name:kAPNetworkDidLoginNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
}
|
|
|
|
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
|
|
|
NSArray *arguments=command.arguments;
|
|
|
|
if (!arguments||[arguments count]<1) {
|
|
|
|
NSLog(@"startLogPageView argument error");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
NSString * pageName=[arguments objectAtIndex:0];
|
|
|
|
if (pageName) {
|
|
|
|
[APService startLogPageView:pageName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-(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) {
|
|
|
|
[APService stopLogPageView:pageName];
|
|
|
|
}
|
|
|
|
|
2014-06-04 13:20:24 +08:00
|
|
|
}
|
|
|
|
|
2014-01-20 18:27:31 +08:00
|
|
|
|
|
|
|
@end
|