mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 14:32:51 +08:00
Update Android_detail_api.md & Optimize JPushPlugin.js
This commit is contained in:
parent
3adbc003b0
commit
637624edab
@ -157,6 +157,19 @@
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
|
||||
### API - clearNotificationById
|
||||
根据通知 Id 清除通知(包括本地通知)。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.clearNotificationById(notificationId)
|
||||
|
||||
#### 参数说明
|
||||
- notificationId:int,通知的 id。
|
||||
|
||||
#### 代码示例
|
||||
|
||||
window.plugins.jPushPlugin.clearNotificationById(1)
|
||||
|
||||
## 设置允许推送时间
|
||||
|
||||
|
@ -7,10 +7,10 @@ JPushPlugin.prototype.openNotification = {}
|
||||
JPushPlugin.prototype.receiveNotification = {}
|
||||
|
||||
JPushPlugin.prototype.isPlatformIOS = function () {
|
||||
var isPlatformIOS = device.platform == 'iPhone'
|
||||
|| device.platform == 'iPad'
|
||||
|| device.platform == 'iPod touch'
|
||||
|| device.platform == 'iOS'
|
||||
var isPlatformIOS = device.platform == 'iPhone' ||
|
||||
device.platform == 'iPad' ||
|
||||
device.platform == 'iPod touch' ||
|
||||
device.platform == 'iOS'
|
||||
return isPlatformIOS
|
||||
}
|
||||
|
||||
@ -26,142 +26,103 @@ JPushPlugin.prototype.call_native = function (name, args, callback) {
|
||||
// public methods
|
||||
JPushPlugin.prototype.init = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('initial', data, null)
|
||||
this.call_native('initial', [], null)
|
||||
} else {
|
||||
data = []
|
||||
this.call_native('init', data, null)
|
||||
this.call_native('init', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getRegistrationID = function (callback) {
|
||||
try {
|
||||
var data = []
|
||||
this.call_native('getRegistrationID', [data], callback)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
this.call_native('getRegistrationID', [], callback)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopPush = function () {
|
||||
data = []
|
||||
this.call_native('stopPush', data, null)
|
||||
this.call_native('stopPush', [], null)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.resumePush = function () {
|
||||
data = []
|
||||
this.call_native('resumePush', data, null)
|
||||
this.call_native('resumePush', [], null)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.isPushStopped = function (callback) {
|
||||
data = []
|
||||
this.call_native('isPushStopped', data, callback)
|
||||
this.call_native('isPushStopped', [], callback)
|
||||
}
|
||||
|
||||
// iOS methods
|
||||
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
|
||||
try {
|
||||
if (tags == null) {
|
||||
this.setAlias(alias)
|
||||
return
|
||||
}
|
||||
if (alias == null) {
|
||||
this.setTags(tags)
|
||||
return
|
||||
}
|
||||
var arrayTagWithAlias = [tags]
|
||||
arrayTagWithAlias.unshift(alias)
|
||||
this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
if (tags == null) {
|
||||
this.setAlias(alias)
|
||||
return
|
||||
}
|
||||
if (alias == null) {
|
||||
this.setTags(tags)
|
||||
return
|
||||
}
|
||||
var arrayTagWithAlias = [tags]
|
||||
arrayTagWithAlias.unshift(alias)
|
||||
this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setTags = function (tags) {
|
||||
try {
|
||||
this.call_native('setTags', tags, null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
this.call_native('setTags', tags, null)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setAlias = function (alias) {
|
||||
try {
|
||||
this.call_native('setAlias', [alias], null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
this.call_native('setAlias', [alias], null)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setBadge = function (value) {
|
||||
if (this.isPlatformIOS()) {
|
||||
try {
|
||||
this.call_native('setBadge', [value], null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
this.call_native('setBadge', [value], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.resetBadge = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
try {
|
||||
var data = []
|
||||
this.call_native('resetBadge', [data], null)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
this.call_native('resetBadge', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugModeFromIos = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('setDebugModeFromIos', [data], null)
|
||||
this.call_native('setDebugModeFromIos', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setLogOFF = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('setLogOFF', [data], null)
|
||||
this.call_native('setLogOFF', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setCrashLogON = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('crashLogON', [data], null)
|
||||
this.call_native('crashLogON', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.addLocalNotificationForIOS = function (delayTime, content,
|
||||
badge, notificationID, extras) {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [delayTime, content, badge, notificationID, extras]
|
||||
this.call_native('setLocalNotification', data, null)
|
||||
this.call_native('setLocalNotification', [delayTime, content, badge, notificationID, extras], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (
|
||||
identifierKey) {
|
||||
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (identifierKey) {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [identifierKey]
|
||||
this.call_native('deleteLocalNotificationWithIdentifierKey', data, null)
|
||||
this.call_native('deleteLocalNotificationWithIdentifierKey', [identifierKey], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.clearAllLocalNotifications = function () {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = []
|
||||
this.call_native('clearAllLocalNotifications', data, null)
|
||||
this.call_native('clearAllLocalNotifications', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setLocation = function (latitude, longitude) {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [latitude, longitude]
|
||||
this.call_native('setLocation', data, null)
|
||||
this.call_native('setLocation', [latitude, longitude], null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,11 +173,11 @@ JPushPlugin.prototype.getUserNotificationSettings = function (callback) {
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.addDismissActions = function (actions, categoryId) {
|
||||
this.call_native('addDismissActions', [actions, categoryId])
|
||||
this.call_native('addDismissActions', [actions, categoryId])
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.addNotificationActions = function (actions, categoryId) {
|
||||
this.call_native('addNotificationActions', [actions, categoryId])
|
||||
this.call_native('addNotificationActions', [actions, categoryId])
|
||||
}
|
||||
|
||||
// Android methods
|
||||
@ -228,61 +189,45 @@ JPushPlugin.prototype.setDebugMode = function (mode) {
|
||||
|
||||
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
|
||||
if (device.platform == 'Android') {
|
||||
data = []
|
||||
this.call_native('setBasicPushNotificationBuilder', data, null)
|
||||
this.call_native('setBasicPushNotificationBuilder', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
|
||||
if (device.platform == 'Android') {
|
||||
data = []
|
||||
this.call_native('setCustomPushNotificationBuilder', data, null)
|
||||
this.call_native('setCustomPushNotificationBuilder', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
|
||||
try {
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
|
||||
this.receiveMessage = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
|
||||
} catch(exception) {
|
||||
console.log('JPushPlugin:pushCallback ' + exception)
|
||||
}
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
|
||||
this.receiveMessage = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
|
||||
try {
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
|
||||
this.openNotification = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
|
||||
this.openNotification = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
|
||||
try {
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
|
||||
this.receiveNotification = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
|
||||
} catch(exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
data = JSON.stringify(data)
|
||||
console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
|
||||
this.receiveNotification = JSON.parse(data)
|
||||
cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.clearAllNotification = function () {
|
||||
if (device.platform == 'Android') {
|
||||
data = []
|
||||
this.call_native('clearAllNotification', data, null)
|
||||
this.call_native('clearAllNotification', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.clearNotificationById = function (notificationId) {
|
||||
if (device.platform == 'Android') {
|
||||
data = []
|
||||
this.call_native('clearNotificationById', [notificationId], null)
|
||||
}
|
||||
}
|
||||
@ -302,8 +247,7 @@ JPushPlugin.prototype.setDebugMode = function (mode) {
|
||||
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
|
||||
notificationID, broadcastTime, extras) {
|
||||
if (device.platform == 'Android') {
|
||||
data = [builderId, content, title, notificationID, broadcastTime, extras]
|
||||
this.call_native('addLocalNotification', data, null)
|
||||
this.call_native('addLocalNotification', [builderId, content, title, notificationID, broadcastTime, extras], null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,8 +259,7 @@ JPushPlugin.prototype.removeLocalNotification = function (notificationID) {
|
||||
|
||||
JPushPlugin.prototype.clearLocalNotifications = function () {
|
||||
if (device.platform == 'Android') {
|
||||
data = []
|
||||
this.call_native('clearLocalNotifications', data, null)
|
||||
this.call_native('clearLocalNotifications', [], null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,9 +280,9 @@ JPushPlugin.prototype.setStatisticsOpen = function (mode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于在 Android 6.0 及以上系统,申请一些权限
|
||||
* 具体可看:http://docs.jpush.io/client/android_api/#android-60
|
||||
*/
|
||||
* 用于在 Android 6.0 及以上系统,申请一些权限
|
||||
* 具体可看:http://docs.jpush.io/client/android_api/#android-60
|
||||
*/
|
||||
JPushPlugin.prototype.requestPermission = function () {
|
||||
if (device.platform == 'Android') {
|
||||
this.call_native('requestPermission', [], null)
|
||||
|
Loading…
Reference in New Issue
Block a user