mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-19 05:22:57 +08:00
move jpush sdk inital method to JPushPlugin static method
This commit is contained in:
parent
cbca41a513
commit
40828ff145
@ -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;
|
||||
|
@ -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){
|
||||
|
Loading…
Reference in New Issue
Block a user