神奇的问题1. 退出登录后,会收到重复的两条消息
原因:因为没有调用 removeEventListener 删除监听方法,所以会监听多个
网上找了很多删除监听的方法,终于找到正确的删除监听方法如下,不用bind方法
//去除监听
removeListenNotification() {
document.removeEventListener("jpush.receiveNotification", this.receiveNotification, false);
document.removeEventListener("jpush.openNotification", this.openNotification, false);
}
//监听接收消息
listenReceiveNotification() {
document.addEventListener("jpush.receiveNotification", this.receiveNotification, false);
}
receiveNotification() {
this.storage.set(this.storage.NoticeDataChange, "true");
}
//监听打开消息
listenOpenNotification() {
this.openNotification = this.openNotification.bind(this);//在绑定事件时,不使用bind 绑定this, 绕个弯绑定this (???黑人脸)
document.addEventListener("jpush.openNotification", this.openNotification, false);
}
openNotification(event) {
}
问题2. iOS真机测试可以收到消息,打包收不到消息
用xcode连真机,接收消息接收的很欢乐,一打包交给测试后一条消息都没有收到,好尴尬
解决方法:代码肯定没有问题,Alias也设置成功了,查到最后是开发证书的问题,
打包一直是使用脚本打包,以前设置method="ad-hoc",正确应该设置"development"打开发包
使用xcode打包也一样,构建的时候选择Development,然后导出