mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-04-13 02:43:10 +08:00
add notificatoncenter and track page
This commit is contained in:
parent
334cda7486
commit
599952976f
@ -14,28 +14,98 @@
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
var onDeviceReady = function() {
|
||||
var onDeviceReady = function() {
|
||||
console.log("Device ready!")
|
||||
initiateUI();
|
||||
|
||||
}
|
||||
var onTagsWithAlias = function(data) {
|
||||
try{
|
||||
var tagaliasJson=window.plugins.jPushPlugin.parseEvent(data);
|
||||
$("#tagAliasResult").html(tagaliasJson);;
|
||||
|
||||
}
|
||||
var initiateUI = function() {
|
||||
$("#setTagWithAliasButton").click(function(ev) {
|
||||
console.log("tap set tag/alias button!");
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onDidSetup = function() {
|
||||
try{
|
||||
$("#connectState").html("建立连接");;
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onDidClose = function() {
|
||||
try{
|
||||
$("#connectState").html("连接关闭");;
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onDidRegister = function() {
|
||||
try{
|
||||
$("#connectState").html("注册成功");;
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onDidLogin = function() {
|
||||
try{
|
||||
$("#connectState").html("登录成功");;
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onGetRegistradionID = function(data) {
|
||||
try{
|
||||
var registrationID=window.plugins.jPushPlugin.parseEvent(data);
|
||||
$("#registrationid").html(registrationID);;
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var initiateUI = function() {
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID();
|
||||
window.plugins.jPushPlugin.initNotificationCenter();
|
||||
window.plugins.jPushPlugin.startLogPageView("mianPage");
|
||||
//window.plugins.jPushPlugin.stopLogPageView("mianPage");
|
||||
$("#setTagWithAliasButton").click(function(ev) {
|
||||
|
||||
try{
|
||||
var tag1 = $("#tagText1").attr("value");
|
||||
console.log("tag1:"+tag1);
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.setTagsWithAlias("myTags","myTags1","myTags2","myAlias");
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener("networkDidSetup", onDidSetup, false)
|
||||
document.addEventListener("networkDidClose", onDidClose, false)
|
||||
document.addEventListener("networkDidRegister", onDidRegister, false)
|
||||
document.addEventListener("networkDidLogin", onDidLogin, false)
|
||||
|
||||
document.addEventListener("setTagsWithAlias", onTagsWithAlias, false)
|
||||
document.addEventListener("registrationID", onGetRegistradionID, false)
|
||||
document.addEventListener("deviceready", onDeviceReady, false)
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@ -53,6 +123,12 @@
|
||||
<div data-role="fieldcontain">
|
||||
<center><h3>JPushPlugin Example</h3></center>
|
||||
<span name="alias" id="alias"></span><hr />
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationid">null</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>connected state: </label>
|
||||
<label id="connectState">未连接</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
@ -85,6 +161,10 @@
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasResult" >null</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -41,8 +41,9 @@
|
||||
<framework src="CoreFoundation.framework" weak="true" />
|
||||
<framework src="UIKit.framework" weak="true" />
|
||||
<framework src="CoreTelephony.framework" weak="true" />
|
||||
|
||||
|
||||
<framework src="Security.framework" weak="true" />
|
||||
<framework src="libz.dylib" weak="true" />
|
||||
|
||||
</platform>
|
||||
|
||||
<!-- android -->
|
||||
|
@ -16,4 +16,8 @@
|
||||
-(void)setTags:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setAlias:(CDVInvokedUrlCommand*)command;
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
|
||||
-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command;
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
|
@ -10,7 +10,8 @@
|
||||
#import "APService.h"
|
||||
|
||||
@implementation JPushPlugin
|
||||
|
||||
|
||||
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSArray *arguments=command.arguments;
|
||||
@ -55,11 +56,23 @@
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
|
||||
}
|
||||
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||
NSString* registratonID = [APService registrionID];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//
|
||||
NSString *script=[NSString stringWithFormat:@"cordova.fireDocumentEvent('registrationID','[%@]')",registratonID];
|
||||
[self.commandDelegate evalJs:script];
|
||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.registrationCallback('%@')",registratonID]];
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
||||
|
||||
|
||||
//NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
|
||||
NSLog(@"recode is %d tags is %@ alias %@",resultCode,tags,alias);
|
||||
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:resultCode],@"resultCode",
|
||||
tags==nil?[NSNull null]:[tags allObjects],@"resultTags",
|
||||
@ -68,12 +81,71 @@
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('setTagsWithAlias','[%@]')",jsonString]];
|
||||
|
||||
[self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
||||
});
|
||||
}
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
- (void)networkDidSetup:(NSNotification *)notification {
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidSetup')"]];
|
||||
}
|
||||
|
||||
- (void)networkDidClose:(NSNotification *)notification {
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidClose')"]];
|
||||
}
|
||||
|
||||
- (void)networkDidRegister:(NSNotification *)notification {
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidRegister')"]];
|
||||
}
|
||||
|
||||
- (void)networkDidLogin:(NSNotification *)notification {
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('networkDidLogin')"]];
|
||||
}
|
||||
|
||||
-(void)initNotifacationCenter:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidSetup:)
|
||||
name:kAPNetworkDidSetupNotification
|
||||
object:nil];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidClose:)
|
||||
name:kAPNetworkDidCloseNotification
|
||||
object:nil];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidRegister:)
|
||||
name:kAPNetworkDidRegisterNotification
|
||||
object:nil];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidLogin:)
|
||||
name:kAPNetworkDidLoginNotification
|
||||
object:nil];
|
||||
|
||||
}
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"startLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[APService startLogPageView:pageName];
|
||||
}
|
||||
}
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"stopLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[APService stopLogPageView:pageName];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
cordova.define("cn.jpush.phonegap.JPushPlugin.JPushPlugin", function(require, exports, module) {
|
||||
var JPushPlugin = function(){
|
||||
|
||||
};
|
||||
@ -11,6 +11,67 @@ JPushPlugin.prototype.call_native = function ( name, args) {
|
||||
args);
|
||||
return ret;
|
||||
}
|
||||
JPushPlugin.prototype.getRegistrationID = function () {
|
||||
|
||||
this.call_native( "getRegistrationID", null);
|
||||
|
||||
}
|
||||
JPushPlugin.prototype.startLogPageView = function (data) {
|
||||
if (data==null || typeof(data)=="undefined" || data==""){
|
||||
console.log("argument is null");
|
||||
|
||||
}
|
||||
else{
|
||||
this.call_native( "startLogPageView", [data]);
|
||||
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.stopLogPageView = function (data) {
|
||||
if (data==null || typeof(data)=="undefined" || data==""){
|
||||
console.log("argument is null");
|
||||
|
||||
}
|
||||
else{
|
||||
this.call_native( "stopLogPageView", [data]);
|
||||
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.initNotificationCenter = function () {
|
||||
|
||||
this.call_native( "initNotifacationCenter", null);
|
||||
|
||||
}
|
||||
JPushPlugin.prototype.parseEvent = function (data) {
|
||||
try{
|
||||
var parament=""
|
||||
var count=1;
|
||||
var start=false;
|
||||
for(var i in data){
|
||||
|
||||
if(data[i]=='['){
|
||||
if (count==1&&start==false) {
|
||||
start=true;
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (data[i]==']') {
|
||||
if(count==1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
parament+=data[i]
|
||||
|
||||
}
|
||||
return parament;
|
||||
}
|
||||
catch(exception){
|
||||
alert(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function (tags,alias) {
|
||||
|
||||
@ -52,12 +113,21 @@ JPushPlugin.prototype.pushCallback = function (data) {
|
||||
var code = bToObj.resultCode;
|
||||
var tags = bToObj.resultTags;
|
||||
var alias = bToObj.resultAlias;
|
||||
|
||||
console.log("JPushPlugin:callBack--code is "+code+" tags is "+tags + " alias is "+alias);
|
||||
}
|
||||
catch(exception){
|
||||
|
||||
alert(exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.registrationCallback = function (data) {
|
||||
try{
|
||||
console.log("registrationCallback--registraionID is "+data);
|
||||
}
|
||||
catch(exception){
|
||||
alert(exception);
|
||||
}
|
||||
}
|
||||
if(!window.plugins) {
|
||||
window.plugins = {};
|
||||
}
|
||||
@ -65,3 +135,5 @@ if(!window.plugins.jPushPlugin){
|
||||
window.plugins.jPushPlugin = new JPushPlugin();
|
||||
}
|
||||
module.exports = new JPushPlugin();
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user