From 40828ff145edbdeff007bd24a4ef8be6ce7bdfb9 Mon Sep 17 00:00:00 2001 From: zhangqinghe Date: Tue, 14 Apr 2015 10:05:14 +0800 Subject: [PATCH] move jpush sdk inital method to JPushPlugin static method --- src/ios/Plugins/JPushPlugin.m | 51 ++++++++++++++++------------------- www/JPushPlugin.js | 13 ++++++--- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 08c154b..eb3681a 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -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; diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index bcae17a..a8753d9 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -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){