我想实现pushwoosh离子2我使用this科尔多瓦插件。我是新来的离子2想知道如何使用这个插件的方法。如何实现pushwoosh离子2
1
A
回答
3
首先阅读pushwoosh手册有关使用科尔多瓦插件:http://docs.pushwoosh.com/docs/cordova-phonegap
之后,我得到这个代码,iOS和Android上工作。
在步骤3中,您可以使用下面的代码作为一个服务提供商: 在我的项目文件夹,我创建这个文件:/src/app/providers/push-service.ts
import { Injectable } from "@angular/core";
import { Platform } from 'ionic-angular';
declare var cordova : any;
@Injectable()
export class PushService {
PUSHWOOSH_APP_ID : string = 'XXXXX-XXXXX'; // your pushwoosh app id
GOOGLE_PROJECT_NUMBER: string = 'XXXXXXXXXXXX'; // project number from firebase
constructor(public platform : Platform){
this.platform.ready().then(() => {
if(this.platform.is('ios') || this.platform.is('android')){
console.log("PushwooshService init: Running on push compatible platform "+ this.platform.userAgent() +')');
this.initPushwoosh();
} else{
console.log("PushwooshService init: No compatible platform available. Skipping init.)");
return;
}
});
}
initPushwoosh(){
let pushNotification = cordova.require("pushwoosh-cordova-plugin.PushNotification");
//set push notifications handler
document.addEventListener('push-notification', function (event) {
let message = (event as any).notification.message; // Push message
let userData = (event as any).notification.userdata; // Custom push data
if (userData) {
// handle custom push data here
console.log('user data: ' + JSON.stringify(userData));
}
});
//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_NUMBER", pw_appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({
appid: this.PUSHWOOSH_APP_ID,
projectid: this.GOOGLE_PROJECT_NUMBER
// serviceName: "MPNS_SERVICE_NAME"
});
//register for pushes
pushNotification.registerDevice(
function (status) {
var pushToken = status;
console.log(pushToken);
alert('push token: ' + JSON.stringify(pushToken));
},
function (status) {
alert(JSON.stringify(['failed to register ', status]));
}
);
}
}
现在你可以将此提供程序导入到/src/app/app.component.ts中。
import { PushService } from '../providers/push-service';
@Component({
templateUrl: 'app.html',
providers: [PushService]
})
每当您的应用程序启动时,它将初始化pushwoosh。
祝你好运;)
1
您需要使用
var message = (event as any).notification.message;
而不是
var message = event.notification.message;
相关问题
- 1. 如何实现离子2
- 2. 如何离子实现观察者模式2
- 3. 离子2:如何实现固定顶部面板
- 4. 如何在离子2中实现登录流程?
- 5. 如何离子2
- 6. 离子2拍摄现场
- 7. 实现诸如/不同于离子2火力
- 8. 离子2 - 如何从父
- 9. 如何在离子2
- 10. 如何在离子2
- 11. 离子2:如何使离子2滑块动态
- 12. Firebase离子代码实现
- 13. 如何实现在线/离线同步离子
- 14. 如何获得离子2角2
- 15. 如何使用PushWoosh在Phonegap中实现PushNotifications?
- 16. 安装离子时出现错误2
- 17. push插件没有发现,离子2
- 18. 在离子2
- 19. 对离子2
- 20. 离子2 DatePicker
- 21. 离子2:keycloak
- 22. 离子2:IOS
- 23. NativePageTransitions离子2
- 24. 离子2 FormBuilder
- 25. 与离子2
- 26. 离子2 deeplinking
- 27. 要离子2
- 28. 请离子2
- 29. 如何在solr中实现时间/(距离)^ 2?
- 30. 如何使用离子排和离子排对准离子2中的元素?
是否必须使用Firebase中的项目编号?因为我正在使用mySQL数据库。 – RamshaS
对于android,您需要云消息传递的Firebase项目编号才能发送通知。 – user1980927
谢谢它真的帮助我很多! 但我仍然在event.notification.message错误。你能解释一下'通知'变量来自哪里吗?我的智能感知在通知中显示红线! – RamshaS