mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 14:32:51 +08:00
add message in app
This commit is contained in:
parent
3e55f6f2c4
commit
1af99fe4bf
@ -11,11 +11,24 @@
|
||||
|
||||
@implementation JPushPlugin
|
||||
|
||||
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
||||
if (self=[super initWithWebView:theWebView]) {
|
||||
|
||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kAPNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<2) {
|
||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
||||
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
||||
return ;
|
||||
}
|
||||
NSString *alias=[arguments objectAtIndex:0];
|
||||
@ -51,8 +64,8 @@
|
||||
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSString* registratonID = [APService registrionID];
|
||||
CDVPluginResult *result=[self pluginResultForValue:registratonID];
|
||||
NSString* registrationID = [APService registrionID];
|
||||
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
||||
if (result) {
|
||||
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
||||
} else {
|
||||
@ -78,7 +91,7 @@
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
||||
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
@ -141,5 +154,23 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
||||
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
NSLog(@"%@",userInfo);
|
||||
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
NSLog(@"%@",jsonString);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1,5 +1,3 @@
|
||||
var JPushPlugin = function(){
|
||||
};
|
||||
|
||||
JPushPlugin.prototype.isPlatformIOS = function(){
|
||||
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
||||
@ -76,41 +74,39 @@ JPushPlugin.prototype.setAlias = function(data){
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.recieveMessageInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:pushCallback--data:"+data);
|
||||
var bToObj=JSON.parse(data);
|
||||
var message = bToObj.message;
|
||||
var extras = bToObj.extras;
|
||||
|
||||
console.log(message);
|
||||
console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
console.log(extras['cn.jpush.android.CONTENT_TYPE']);
|
||||
console.log(extras['cn.jpush.android.EXTRA']);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:pushCallback "+exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.recieveMessageIniOSCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:pushCallback--data:"+data);
|
||||
var bToObj=JSON.parse(data);
|
||||
var message = bToObj.message;
|
||||
var extras = bToObj.extras;
|
||||
|
||||
console.log(message);
|
||||
console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
console.log(extras['cn.jpush.android.CONTENT_TYPE']);
|
||||
console.log(extras['cn.jpush.android.EXTRA']);
|
||||
|
||||
console.log("JPushPlugin:recieveMessageIniOSCallback--data:"+data);
|
||||
var bToObj = JSON.parse(data);
|
||||
var content = bToObj.content;
|
||||
console.log(content);
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:pushCallback "+exception);
|
||||
console.log("JPushPlugin:recieveMessageIniOSCallback"+exception);
|
||||
}
|
||||
}
|
||||
//
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log(data);
|
||||
var bToObj = JSON.parse(data);
|
||||
var alert = bToObj.alert;
|
||||
var extras = bToObj.extras;
|
||||
console.log(alert);
|
||||
|
||||
console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
console.log(extras['app']);
|
||||
console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
|
||||
console.log(extras['cn.jpush.android.EXTRA']);
|
||||
console.log(extras['cn.jpush.android.PUSH_ID']);
|
||||
console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
|
||||
console.log("JPushPlugin:openNotificationCallback is ready");
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
console.log(data);
|
||||
|
Loading…
Reference in New Issue
Block a user