PlayFab CloudScript:如何在推送通知中设置大图片(横幅)
如何在PlayFab CloudScript推送通知中添加大图片横幅?
你可以通过PlayFab SendPushNotification API的CustomData字段,传递FCM所需的图片参数来实现大图片横幅效果,对应你在Firebase控制台中设置的“图片URL”功能。
修改后的完整代码
handlers.sendPushNotification = (args, context) => { try { const bigPictureUrl = "https://firebasestorage.googleapis.com/v0/b/project-id.appspot.com/o/FCMImages%2Fnotification-banner-7.png"; server.SendPushNotification({ Recipient: currentPlayerId, Package: { Title: "Test", Message: "This is a test", // 添加自定义FCM负载,设置大图片URL CustomData: { "notification": { "image": bigPictureUrl } } } }); return {}; } catch (err) { // 可选:添加错误日志便于排查 server.WritePlayerEvent({ EventName: "PushNotificationError", Body: { Error: err.message } }); return { Error: err.message }; } };
关键说明
- PlayFab的
CustomData会直接作为FCM推送负载的一部分传递,这里的notification.image对应Firebase控制台中设置的图片URL,适用于系统自动展示的通知消息。 - 如果你的客户端是自定义处理推送(数据消息模式),则需要改用
data字段传递参数,示例如下:
这种情况下,你需要在客户端代码中解析CustomData: { "data": { "big_picture": bigPictureUrl } }big_picture字段并手动展示图片。
内容的提问来源于stack exchange,提问作者Hasan Yousef
相关产品推荐
相关产品推荐

