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{ +(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
_luanchOptions=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{ - (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
if (self=[super initWithWebView:theWebView]) { if (self=[super initWithWebView:theWebView]) {
@ -35,40 +43,27 @@ static NSDictionary *_luanchOptions=nil;
object:nil]; object:nil];
if (!_luanchOptions) { if (!_luanchOptions) {
return; NSDictionary *userInfo = [_luanchOptions
} valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSDictionary *userInfo = [_luanchOptions if ([userInfo count] >0) {
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; NSError *error;
if (_luanchOptions && [userInfo count] >0) { NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
NSError *error; NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error]; if (!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]];
dispatch_async(dispatch_get_main_queue(), ^{ });
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
}); }
} }
} }
} }
return self; 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{ -(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSArray *arguments=command.arguments; NSArray *arguments=command.arguments;

View File

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