当前行为: 我用过push插件。当我尝试为推送操作定义回调方法时发生以下错误
[ts]类型'“accept”'的参数不能分配给'PushEvent'类型的参数。
[ts]类型'“reject”'的参数不能分配给'PushEvent'类型的参数。
相关代码:
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
} else {
console.log('We do not have permission to send push notifications');
}
});
const options: PushOptions = {
android: {},
ios: {
alert: true,
badge: true,
sound: true,
"categories": {
"invite": {
"yes": {
"callback": "accept", "title": "Accept", "foreground": true, "destructive": false
},
"no": {
"callback": "reject", "title": "Reject", "foreground": true, "destructive": false
},
"maybe": {
"callback": "maybe", "title": "Maybe", "foreground": false, "destructive": false
}
},
"delete": {
"yes": {
"callback": "doDelete", "title": "Delete", "foreground": false, "destructive": true
},
"no": {
"callback": "cancel", "title": "Cancel", "foreground": false, "destructive": false
}
}
}
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', JSON.stringify(notification)));
pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', JSON.stringify(registration)));
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
pushObject.on('accept').subscribe(obj => console.log('accept a notification', JSON.stringify(obj)));
pushObject.on('reject').subscribe(obj => console.log('reject a notification', JSON.stringify(obj)));
其他信息:
package.json info:
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "2.4.8",
"@angular/compiler": "2.4.8",
"@angular/compiler-cli": "2.4.8",
"@angular/core": "2.4.8",
"@angular/forms": "2.4.8",
"@angular/http": "2.4.8",
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/platform-server": "2.4.8",
"@ionic-native/barcode-scanner": "^4.1.0",
"@ionic-native/battery-status": "^4.1.0",
"@ionic-native/broadcaster": "^4.1.0",
"@ionic-native/call-number": "^4.0.1",
"@ionic-native/camera": "^4.0.0",
"@ionic-native/core": "^3.6.1",
"@ionic-native/device-orientation": "^4.1.0",
"@ionic-native/email-composer": "^4.0.0",
"@ionic-native/file": "^4.0.1",
"@ionic-native/local-notifications": "^4.1.0",
"@ionic-native/network": "^4.0.0",
"@ionic-native/push": "^4.3.3",
"@ionic-native/qr-scanner": "^4.1.0",
"@ionic-native/screen-orientation": "^4.0.0",
"@ionic-native/screenshot": "^4.1.0",
"@ionic-native/sms": "^4.0.0",
"@ionic-native/social-sharing": "^4.0.0",
"@ionic-native/sqlite": "^4.0.1",
"@ionic/storage": "2.0.0",
"call-number": "0.0.2",
"com.darktalker.cordova.screenshot": "^0.1.6",
"cordova-android": "^6.3.0",
"cordova-ios": "^4.5.2",
"cordova-plugin-app-event": "file:node_modules/cordova-plugin-app-event",
"cordova-plugin-battery-status": "^1.2.4",
"cordova-plugin-broadcaster": "^2.3.0",
"cordova-plugin-camera": "^2.4.1",
"cordova-plugin-compat": "^1.2.0",
"cordova-plugin-console": "^1.1.0",
"cordova-plugin-device": "^1.1.6",
"cordova-plugin-device-orientation": "^1.0.7",
"cordova-plugin-email-composer": "^0.8.11",
"cordova-plugin-file": "^4.3.3",
"cordova-plugin-network-information": "^1.3.3",
"cordova-plugin-qrscanner": "^2.5.0",
"cordova-plugin-screen-orientation": "^2.0.1",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.3",
"cordova-plugin-whitelist": "^1.3.2",
"cordova-plugin-x-socialsharing": "^5.2.1",
"cordova-sms-plugin": "^0.1.11",
"cordova-sqlite-storage": "^2.0.4",
"de.appplant.cordova.plugin.local-notification": "^0.8.5",
"es6-promise-plugin": "^4.1.0",
"ion-multi-picker": "^1.2.0",
"ionic-angular": "2.2.0",
"ionic-native": "2.4.1",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"lodash": "^4.17.4",
"phonegap-plugin-barcodescanner": "^6.0.8",
"phonegap-plugin-push": "^1.10.5",
"pouchdb": "^6.3.4",
"pouchdb-find": "^6.3.4",
"relational-pouch": "^2.1.0",
"rxjs": "5.0.1",
"sw-toolbox": "3.4.0",
"zone.js": "0.7.2"
},
"devDependencies": {
"@ionic/app-scripts": "^2.0.2",
"@ionic/cli-plugin-cordova": "1.6.1",
"@ionic/cli-plugin-ionic-angular": "1.4.1",
"ionic": "3.16.0",
"typescript": "2.0.9"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard",
"cordova-plugin-splashscreen"
],
"cordovaPlatforms": [],
"description": "new: An Ionic project",
"cordova": {
"platforms": [
"android",
"ios"
],
"plugins": {
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-plugin-email-composer": {},
"cordova-sms-plugin": {},
"cordova-plugin-x-socialsharing": {},
"cordova-plugin-screen-orientation": {},
"cordova-plugin-network-information": {},
"cordova-plugin-battery-status": {},
"cordova-plugin-camera": {
"CAMERA_USAGE_DESCRIPTION": " ",
"PHOTOLIBRARY_USAGE_DESCRIPTION": " "
},
"mx.ferreyra.callnumber": {},
"call-number": {},
"cordova-sqlite-storage": {},
"cordova-plugin-file": {},
"de.appplant.cordova.plugin.local-notification": {},
"com.darktalker.cordova.screenshot": {},
"cordova-plugin-broadcaster": {},
"phonegap-plugin-push": {
"SENDER_ID": "85075801930"
}
}
}
}
答案 0 :(得分:0)
它清楚地显示错误号?
错误:强>
类型'“accept”'的参数不能分配给类型的参数 'PushEvent'。
类型'“reject”'的参数不能分配给类型的参数 'PushEvent'。
<强>解决方案:强>
您不能将accept
和reject
用作PushEvent
。它只有notification
,registration
和error
。
以下是the doc: