我试图通过邮递员和Firebase推送通知,但我在iOS通知方面遇到了一些问题。 我想Firebase配置是正确的,因为我之前有一个无效的apns凭据错误,现在我已经成功了。
所以,这是我的邮递员:
这是我使用
的代码initPushNotification() {
if (!this.platform.is('cordova')) {
console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
return;
}
const options: PushOptions = {
android: {
senderID: "883847118563"
},
ios: {
senderID: "883847118563"
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('registration').subscribe((data: any) => {
console.log("device token ->", data.registrationId);
localStorage.setItem("pushToken", data.registrationId);
let alert = this.alertCtrl.create({
title: 'device token',
subTitle: data.registrationId,
buttons: ['OK']
});
alert.present();
});
pushObject.on('notification').subscribe((data: any) => {
console.log('message', data.message);
if (data.additionalData.foreground) {
let confirmAlert = this.alertCtrl.create({
title: 'New Notification',
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
// this.nav.push(DetailsPage, {message: data.message});
}
}]
});
confirmAlert.present();
} else {
// this.nav.push(DetailsPage, {message: data.message})
let alert = this.alertCtrl.create({ // o que fazer quando clica na app
title: 'clicked on',
subTitle: "you clicked on the notification!",
buttons: ['OK']
});
alert.present();
console.log("Push notification clicked");
}
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
这是我的云设置:
const cloudSettings: CloudSettings = {
'core': {
'app_id': 'bde818c3' // ID da app @https://apps.ionic.io/apps/
},
'push': {
'sender_id': '883847118563',
'pluginConfig': {
'ios': {
'badge': true,
'sound': true
},
'android': {
'iconColor': '#ff0000'
}
}
}
};
请注意,此处的一些代码仅用于测试。 所以,我的Android收到通知没有问题,但ipad无法接收它。我已经给应用程序发布了关于ios设置的通知... 有什么建议? 谢谢你的帮助。
答案 0 :(得分:0)
您是否实施了接收通知的方法?
extension AppDelegate: UNUserNotificationCenterDelegate{
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print full message.
print(userInfo)
// Change this to your preferred presentation option
completionHandler([.alert,.sound])
}
}