简体   繁体   English

在 iOS 模拟器上测试 FCM 通知

[英]Test FCM notification on iOS Simulator

Since Xcode 11, iOS simulators can now receive push notifications.自 Xcode 11 起,iOS 模拟器现在可以接收推送通知。 This can be accomplished by executing a specific command or providing a JSON file to the simulator.这可以通过执行特定命令或向模拟器提供 JSON 文件来完成。 I got this information from this blog: Test Notification on Simulator .我从这个博客中获得了这些信息: 在模拟器上测试通知

However, in my use case, I use Firebase Cloud Messaging to deliver notifications to the user of my app (Android and iOS both).但是,在我的用例中,我使用 Firebase Cloud Messaging 向我的应用程序的用户发送通知(Android 和 iOS 两者)。 I am unable to test the notification generated by Firebase on a simulator as the payload is different for FCM.我无法在模拟器上测试 Firebase 生成的通知,因为 FCM 的负载不同。

Is there a way to achieve this?有没有办法做到这一点?
I found a similar question on the topic but there's no answer on it so far.我在该主题上发现了类似的问题,但到目前为止还没有答案。

For Testing push notifiction in simulator just creat a new file and paste following json object and save file in .apns , and then just drag and drop this file in simulator then push will work.对于在模拟器中测试推送通知,只需创建一个新文件并粘贴以下 json 对象并将文件保存在 .apns 中,然后只需将此文件拖放到模拟器中,然后推送即可。

{
    "aps" : {
        "alert" : {
            "title" : "sarunw.com",
            "body" : "A asdfsadfsadf"
        },
        "badge" : 5
    },
    "Simulator Target Bundle": "bundleId"
}

For differenct payload just use following JSON object in Postman对于不同的有效负载,只需在 Postman 中使用以下 JSON 对象

{
 "to" : "ewebWDSSwYc:APA91bGOARO4eq9LlOfgfXPQZMK3IiRFanhzSSgkD6cVqJiPbnyuEgsvQMarDEl6Hg7_UMtFM6Hn90jyTsSENNqLNNLVjLSypR0voAO3j6orIsgabX-t0cpfJ0qpB2SzhZiXvor0r__d",
 "notification":
 {
    "title":"ABC",
    "body":"123",
    "mutable_content" : true,
    "category":"CustomSamplePush"
 },
 
 "data":
    {
        "sender_contact_code" : "+92",
     "sender_contact" : "(555) 564-8583",
     "group_name":"Testing Group",
     "type":"NewMessage",
     "type_id":"1213",
     "notification_type_id":"123213"
    }
}

with this url -> https://fcm.googleapis.com/fcm/send (Type will be POST)and in authorization you need to put Server key in Key Value, in that way you will be able to send push notification with your own formatted object.使用此 url -> https://fcm.googleapis.com/fcm/send (类型将为 POST)并且在授权中您需要将服务器密钥放入键值中,这样您就可以使用您的自己的格式化对象。

also you can use Pusher for testing push notifiction & I have uploaded screenshot for reference.您也可以使用 Pusher 来测试推送通知,我已经上传了截图以供参考。

postman_screenshot

maybe you found the solution a long time ago but here is how i made it work: to allow FCM notification to be catch in your app you need to add that in your.apns file也许您很久以前就找到了解决方案,但我是这样实现的:要允许在您的应用程序中捕获 FCM 通知,您需要将其添加到您的 .apns 文件中

"gcm.message_id":"20021"

here is the apns file i use to test FCM notifs on my Iphone simulator:这是我用来在我的 Iphone 模拟器上测试 FCM notifs 的 apns 文件:

 { "Simulator Target Bundle": "XXX.XXXXXX.XXX", "aps": { "alert": { "title": "Test notif", "body": "Should update widget && refresh feed" }, }, "gcm.message_id":"20021", "data": {} }

Since Xcode 12 (not 11), it's possible to registrer to push and receive via the APNS payload.从 Xcode 12(不是 11)开始,注册者可以通过 APNS 负载进行推送和接收。 If the drag & drop it not working, you can use Terminal :如果拖放不起作用,您可以使用终端:

xcrun simctl push booted YOUR_BUNDLE payload.json

With :和 :

  • "booted" = the current simulator “启动”=当前模拟器
  • "payload.json" = the APNS file on your Mac. “payload.json” = Mac 上的 APNS 文件。

It may look like:它可能看起来像:

{
    "Simulator Target Bundle": "xxx.xxx.xx ",
    "aps":{
                    "alert":{
                        "title":"XXX",
                        "body":"YYY YYYY"
                    },
                    "badge" : 5,
                    "data":{
                        // stuff
                    },
                    "mutable-content":1
                }
}
 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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