简体   繁体   中英

iOS device not receiving push notification from Firebase Cloud Function

I've created an Ionic chat app with firebase cloud functions. The push notifications are working with Android but not ios.

 async getIosToken(token: string, userId: string): Promise<void> { if (!FCM.hasPermission()) { FCM.requestPushPermission() .then(async (hasPerm) => { if (hasPerm) { const iosToken = await FCM.getAPNSToken(); if (iosToken === token) { return; } else { this.saveToken(iosToken, userId); } } }); } else { const iosToken = await FCM.getAPNSToken(); if (iosToken === token) { return; } else { this.saveToken(iosToken, userId); } } } saveToken(token: string, userId: string): void { this.userSvc.saveTokenToFirestore(token, userId) .then(() => { this.storageSvc.setDeviceToken(token); }); }

The iOS token is being saved to firebase...although it never prompted the user for request permissions.

I console logged the firebase cloud function and I can see the APNs token.

 import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; admin.initializeApp(); exports.newChatNotification = functions.firestore .document(`chat/{id}/messages/{doc}`) .onWrite(async event => { const message = event.after.data(); let data: any; let device: any; const db = admin.firestore(); console.log('message', message); console.log('db', db); if (message) { data = message; } const receivingUserId = data ? data.receivingUserId : ''; const content = data ? data.content : ''; const sendingUserId = data ? data.sendingUserId : ''; console.log('payload', receivingUserId, sendingUserId); const payload = { notification: { title: 'New message', body: `${content}`, click_action: 'FCM_PLUGIN_ACTIVITY' }, data: { page: 'tabs/travel-buddies', } }; console.log('payload2', payload); const devicesRef = (await db.collection('devices').doc(`${receivingUserId}`).get()).data(); if (devicesRef) { device = devicesRef; } const token = device ? device.token : ''; console.log('devicesRef', devicesRef, token); return admin.messaging().sendToDevice(token, payload); });

Here's the firebase cloud function console

消息日志

I'm not sure how to troubleshoot why ios is not receiving a push notification because there aren't any errors and I'm getting the APNs token.

I've also tried updating the build system per Google searches online: 在此处输入图片说明 Any help would be greatly appreciated.

您是否已授予您 Apple 帐户的许可?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM