Firebaseのクラウド機能を介して正常に通知を送信すると、通知はiosデバイスでプッシュ通知として表示されません。私は同様の問題のカップルを見つけましたが、明らかな解決策はありません。Firebaseのクラウド機能sendToDeviceがiosで通知として表示されない
クラウド機能:
exports.sendInitialNotification = functions.database.ref('branches/{branchId}/notifications/{notifId}').onWrite(event => {
const data = event.data.val()
if (data.finished) return
const tokens = []
const notifId = event.params.notifId
const getPayload = admin.database().ref(`notifications/${notifId}`).once('value').then(snapshot => {
const notif = snapshot.val()
const payload = {
notification: {
title: notif.title,
body: notif.message,
},
data: {
'title': notif.title,
'message': notif.message,
'id': String(notif.id),
}
}
if (notif.actions) {
payload.data['actions'] = JSON.stringify(notif.actions)
}
console.log('payload:', payload)
return payload
}, (error) => {
console.log('error at sendInitialNotification getPayload():', error)
})
const getTokens = admin.database().ref(`notifications/${notifId}/users`).once('value').then(snapshot => {
const users = snapshot.forEach((data) => {
let promise = admin.database().ref(`users/${data.key}/profile/deviceToken`).once('value').then(snap => {
if (tokens.indexOf(snap.val()) !== -1 || !snap.val()) return
return snap.val()
}, (error) => {
console.log('error retrieving tokens:', error)
})
tokens.push(promise)
})
return Promise.all(tokens)
}, (error) => {
console.log('error at sendInitialNotification getTokens()', error)
}).then((values) => {
console.log('tokens:', values)
return values
})
return Promise.all([getTokens, getPayload]).then(results => {
const tokens = results[0]
const payload = results[1]
if (payload.actions) {
payload.actions = JSON.stringify(payload.actions)
}
const options = {
priority: "high",
}
admin.messaging().sendToDevice(tokens, payload, options)
.then(response => {
data.finished = true
admin.database().ref(`notifications/${notifId}`).update({success: true, successCount: response.successCount})
console.log('successfully sent message', response)
}).catch(error => {
data.finished = true
admin.database().ref(`notifications/${notifId}`).update({success: false, error: error})
console.log('error sending message:', error)
})
})
})
...とfirebaseコンソールでログ:
successfully sent message { results: [ { error: [Object] } ],
canonicalRegistrationTokenCount: 0, failureCount: 1, successCount: 0, multicastId: 7961281827678412000 }tokens: [ 'eS_Gv0FrMC4:APA91bEBk7P1lz...' ]
payload: { notification: { title: 'test07', body: 'test07' }, data: { title: 'test07', message: 'test07', id: '1502383526361' } }
...しかし、iphoneに示されていない通知、悲しいかな。私はここでOOO(オペレーションの順序)に沿って何かを見逃していると確信していますが、どこにいじっているのかはわかりません。誰かが私の欠陥を指摘することができれば、公に罵倒するよう自由に感じてください。
いつもありがとうございましたので、あらゆる方向性に感謝します!
、ハウスキーピングのおかげで...さらに調査では、これは今までに成長している・イン・普及と関連すると表示されます。「無効なのAPNs証明書の設定で証明書を確認してください。」。私は作成し、新しいキーをアップロードしました:APNsの認証キーは、ドキュメントで指示されたが、まだ送信されたすべての通知でエラーが表示されます...紛失! – studiobrain
こんにちはスタジオブレイン。 [Postman](https://stackoverflow.com/documentation/firebase-cloud-messaging/8242/firebase-cloud-messaging/26577/sending-downstream-messages-using-postman#t)からsimoleテストの通知を送信しようとしましたか? = 201701200926242458096)、そこから動作するかどうかを確認します。それはあなたに良いエラーメッセージを与えるかもしれません。 –
私は持っています。私が見ていた問題は、xcodeの逆ドメインIDがfirebaseにあったものと一致しないためでした。それは今働いている。 – studiobrain