mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-02-07 19:32:51 +08:00
add message in app
This commit is contained in:
parent
3e55f6f2c4
commit
1af99fe4bf
@ -11,11 +11,24 @@
|
|||||||
|
|
||||||
@implementation JPushPlugin
|
@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{
|
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
NSArray *arguments=command.arguments;
|
NSArray *arguments=command.arguments;
|
||||||
if (!arguments||[arguments count]<2) {
|
if (!arguments||[arguments count]<2) {
|
||||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
NSString *alias=[arguments objectAtIndex:0];
|
NSString *alias=[arguments objectAtIndex:0];
|
||||||
@ -51,8 +64,8 @@
|
|||||||
|
|
||||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||||
|
|
||||||
NSString* registratonID = [APService registrionID];
|
NSString* registrationID = [APService registrionID];
|
||||||
CDVPluginResult *result=[self pluginResultForValue:registratonID];
|
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
||||||
if (result) {
|
if (result) {
|
||||||
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
||||||
} else {
|
} else {
|
||||||
@ -78,7 +91,7 @@
|
|||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
[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;
|
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
|
@end
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
var JPushPlugin = function(){
|
|
||||||
};
|
|
||||||
|
|
||||||
JPushPlugin.prototype.isPlatformIOS = function(){
|
JPushPlugin.prototype.isPlatformIOS = function(){
|
||||||
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
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){
|
JPushPlugin.prototype.recieveMessageIniOSCallback = function(data){
|
||||||
try{
|
try{
|
||||||
console.log("JPushPlugin:pushCallback--data:"+data);
|
console.log("JPushPlugin:recieveMessageIniOSCallback--data:"+data);
|
||||||
var bToObj = JSON.parse(data);
|
var bToObj = JSON.parse(data);
|
||||||
var message = bToObj.message;
|
var content = bToObj.content;
|
||||||
var extras = bToObj.extras;
|
console.log(content);
|
||||||
|
|
||||||
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){
|
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){
|
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||||
try{
|
try{
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
Loading…
Reference in New Issue
Block a user