move jpush sdk inital method to JPushPlugin static method

This commit is contained in:
zhangqinghe 2015-04-14 10:05:14 +08:00
parent cbca41a513
commit 40828ff145
2 changed files with 32 additions and 32 deletions

View File

@ -17,9 +17,17 @@ static NSDictionary *_luanchOptions=nil;
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_luanchOptions=theLaunchOptions;
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
[APService setupWithOption:_luanchOptions];
}
-(void)initial:(CDVInvokedUrlCommand*)command{
//do nithng,because Cordova plugin use lazy load mode.
}
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
if (self=[super initWithWebView:theWebView]) {
@ -35,40 +43,27 @@ static NSDictionary *_luanchOptions=nil;
object:nil];
if (!_luanchOptions) {
return;
}
NSDictionary *userInfo = [_luanchOptions
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (_luanchOptions && [userInfo count] >0) {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
if (!error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
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) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
});
}
}
}
}
return self;
}
-(void)init:(CDVInvokedUrlCommand*)command{
if (!_luanchOptions) {
NSLog("must set [JPushPlugin setLaunchOptions:launchOptions] in AppDelegate.m"):
return;
}
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
UIUserNotificationTypeSound |
UIUserNotificationTypeAlert)
categories:nil];
[APService setupWithOption:_luanchOptions];
}
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments;

View File

@ -230,10 +230,15 @@ JPushPlugin.prototype.isPushStopped = function(callback){
}
JPushPlugin.prototype.init = function(){
if(device.platform == "Android") {
data=[];
this.call_native("init",data,null);
}
if(this.isPlatformIOS()){
var data=[];
this.call_native("initial",data,null);
}else{
data=[];
this.call_native("init",data,null);
}
}
JPushPlugin.prototype.setDebugMode = function(mode){