mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-01-28 00:00:03 +08:00
Update Android SDK to v3.1.5
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { NavController } from 'ionic-angular';
|
||||
import { JPush } from '@jiguang-ionic/jpush';
|
||||
import { Device } from '@ionic-native/device';
|
||||
import { Component } from "@angular/core";
|
||||
import { NavController } from "ionic-angular";
|
||||
import { JPush } from "@jiguang-ionic/jpush";
|
||||
import { Device } from "@ionic-native/device";
|
||||
|
||||
@Component({
|
||||
selector: 'page-home',
|
||||
templateUrl: 'home.html'
|
||||
selector: "page-home",
|
||||
templateUrl: "home.html"
|
||||
})
|
||||
export class HomePage {
|
||||
|
||||
public registrationId: string;
|
||||
|
||||
devicePlatform: string;
|
||||
@@ -17,139 +16,161 @@ export class HomePage {
|
||||
tagResultHandler = function(result) {
|
||||
var sequence: number = result.sequence;
|
||||
var tags: Array<string> = result.tags == null ? [] : result.tags;
|
||||
alert('Success!' + '\nSequence: ' + sequence + '\nTags: ' + tags.toString());
|
||||
alert(
|
||||
"Success!" + "\nSequence: " + sequence + "\nTags: " + tags.toString()
|
||||
);
|
||||
};
|
||||
|
||||
aliasResultHandler = function(result) {
|
||||
var sequence: number = result.sequence;
|
||||
var alias: string = result.alias;
|
||||
alert('Success!' + '\nSequence: ' + sequence + '\nAlias: ' + alias);
|
||||
alert("Success!" + "\nSequence: " + sequence + "\nAlias: " + alias);
|
||||
};
|
||||
|
||||
errorHandler = function(err) {
|
||||
var sequence: number = err.sequence;
|
||||
var code = err.code;
|
||||
alert('Error!' + '\nSequence: ' + sequence + '\nCode: ' + code);
|
||||
alert("Error!" + "\nSequence: " + sequence + "\nCode: " + code);
|
||||
};
|
||||
|
||||
constructor(public navCtrl: NavController, public jpush: JPush, device: Device) {
|
||||
|
||||
constructor(
|
||||
public navCtrl: NavController,
|
||||
public jpush: JPush,
|
||||
device: Device
|
||||
) {
|
||||
this.devicePlatform = device.platform;
|
||||
|
||||
document.addEventListener('jpush.openNotification', (event: any) => {
|
||||
alert('jpush.openNotification' + JSON.stringify(event));
|
||||
this.jpush.setBadge(0);
|
||||
this.jpush.setApplicationIconBadgeNumber(0);
|
||||
})
|
||||
|
||||
document.addEventListener('jpush.receiveNotification', (event: any) => {
|
||||
var content;
|
||||
if (this.devicePlatform == 'Android') {
|
||||
content = event.alert;
|
||||
} else {
|
||||
content = event.aps.alert;
|
||||
}
|
||||
alert('Receive notification: ' + JSON.stringify(event));
|
||||
|
||||
this.jpush.setBadge(0);
|
||||
this.jpush.setApplicationIconBadgeNumber(0);
|
||||
}, false);
|
||||
|
||||
document.addEventListener('jpush.openNotification', (event: any) => {
|
||||
var content;
|
||||
if (this.devicePlatform == 'Android') {
|
||||
content = event.alert;
|
||||
} else { // iOS
|
||||
if (event.aps == undefined) { // 本地通知
|
||||
content = event.content;
|
||||
} else { // APNS
|
||||
document.addEventListener(
|
||||
"jpush.receiveNotification",
|
||||
(event: any) => {
|
||||
var content;
|
||||
if (this.devicePlatform == "Android") {
|
||||
content = event.alert;
|
||||
} else {
|
||||
content = event.aps.alert;
|
||||
}
|
||||
}
|
||||
alert('open notification: ' + JSON.stringify(event));
|
||||
}, false);
|
||||
alert("Receive notification: " + JSON.stringify(event));
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
document.addEventListener('jpush.receiveLocalNotification', (event: any) => {
|
||||
// iOS(*,9) Only , iOS(10,*) 将在 jpush.openNotification 和 jpush.receiveNotification 中触发。
|
||||
var content;
|
||||
if (this.devicePlatform == 'Android') {
|
||||
} else {
|
||||
content = event.content;
|
||||
}
|
||||
alert('receive local notification: ' + JSON.stringify(event));
|
||||
}, false);
|
||||
document.addEventListener(
|
||||
"jpush.openNotification",
|
||||
(event: any) => {
|
||||
var content;
|
||||
if (this.devicePlatform == "Android") {
|
||||
content = event.alert;
|
||||
} else {
|
||||
// iOS
|
||||
if (event.aps == undefined) {
|
||||
// 本地通知
|
||||
content = event.content;
|
||||
} else {
|
||||
// APNS
|
||||
content = event.aps.alert;
|
||||
}
|
||||
}
|
||||
alert("open notification: " + JSON.stringify(event));
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
document.addEventListener(
|
||||
"jpush.receiveLocalNotification",
|
||||
(event: any) => {
|
||||
// iOS(*,9) Only , iOS(10,*) 将在 jpush.openNotification 和 jpush.receiveNotification 中触发。
|
||||
var content;
|
||||
if (this.devicePlatform == "Android") {
|
||||
} else {
|
||||
content = event.content;
|
||||
}
|
||||
alert("receive local notification: " + JSON.stringify(event));
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
getRegistrationID() {
|
||||
this.jpush.getRegistrationID()
|
||||
.then(rId => {
|
||||
this.registrationId = rId;
|
||||
});
|
||||
this.jpush.getRegistrationID().then(rId => {
|
||||
this.registrationId = rId;
|
||||
});
|
||||
}
|
||||
|
||||
setTags() {
|
||||
this.jpush.setTags({ sequence: this.sequence++, tags: ['Tag1', 'Tag2']})
|
||||
this.jpush
|
||||
.setTags({ sequence: this.sequence++, tags: ["Tag1", "Tag2"] })
|
||||
.then(this.tagResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
addTags() {
|
||||
this.jpush.addTags({ sequence: this.sequence++, tags: ['Tag3', 'Tag4']})
|
||||
this.jpush
|
||||
.addTags({ sequence: this.sequence++, tags: ["Tag3", "Tag4"] })
|
||||
.then(this.tagResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
checkTagBindState() {
|
||||
this.jpush.checkTagBindState({ sequence: this.sequence++, tag: 'Tag1' })
|
||||
this.jpush
|
||||
.checkTagBindState({ sequence: this.sequence++, tag: "Tag1" })
|
||||
.then(result => {
|
||||
var sequence = result.sequence;
|
||||
var tag = result.tag;
|
||||
var isBind = result.isBind;
|
||||
alert('Sequence: ' + sequence + '\nTag: ' + tag + '\nIsBind: ' + isBind);
|
||||
}).catch(this.errorHandler);
|
||||
alert(
|
||||
"Sequence: " + sequence + "\nTag: " + tag + "\nIsBind: " + isBind
|
||||
);
|
||||
})
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
deleteTags() {
|
||||
this.jpush.deleteTags({ sequence: this.sequence++, tags: ['Tag4']})
|
||||
this.jpush
|
||||
.deleteTags({ sequence: this.sequence++, tags: ["Tag4"] })
|
||||
.then(this.tagResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
getAllTags() {
|
||||
this.jpush.getAllTags({ sequence: this.sequence++ })
|
||||
this.jpush
|
||||
.getAllTags({ sequence: this.sequence++ })
|
||||
.then(this.tagResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
cleanTags() {
|
||||
this.jpush.cleanTags({ sequence: this.sequence++ })
|
||||
this.jpush
|
||||
.cleanTags({ sequence: this.sequence++ })
|
||||
.then(this.tagResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
setAlias() {
|
||||
this.jpush.setAlias({ sequence: this.sequence++, alias: 'TestAlias' })
|
||||
this.jpush
|
||||
.setAlias({ sequence: this.sequence++, alias: "TestAlias" })
|
||||
.then(this.aliasResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
getAlias() {
|
||||
this.jpush.getAlias({ sequence: this.sequence++ })
|
||||
this.jpush
|
||||
.getAlias({ sequence: this.sequence++ })
|
||||
.then(this.aliasResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
deleteAlias() {
|
||||
this.jpush.deleteAlias({ sequence: this.sequence++ })
|
||||
this.jpush
|
||||
.deleteAlias({ sequence: this.sequence++ })
|
||||
.then(this.aliasResultHandler)
|
||||
.catch(this.errorHandler);
|
||||
}
|
||||
|
||||
addLocalNotification() {
|
||||
if (this.devicePlatform == 'Android') {
|
||||
this.jpush.addLocalNotification(0, 'Hello JPush', 'JPush', 1, 5000);
|
||||
if (this.devicePlatform == "Android") {
|
||||
this.jpush.addLocalNotification(0, "Hello JPush", "JPush", 1, 5000);
|
||||
} else {
|
||||
this.jpush.addLocalNotificationForIOS(5, 'Hello JPush', 1, 'localNoti1');
|
||||
this.jpush.addLocalNotificationForIOS(5, "Hello JPush", 1, "localNoti1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user