如何在IOS模拟器Xcode中测试PushNotification?

问题描述 投票:0回答:1

如何在不使用ios设备的情况下使用Xcode 11.4及以上版本在IOS模拟器中测试推送通知。

ios xcode apple-push-notifications ios-simulator
1个回答
2
投票

Xcode 11.4及以上版本支持使用模拟器测试推送通知。

要测试

方案1 - 使用Paul Hudson(《中国制造》的作者)创建的 "ControlRoom "Mac应用程序。https:/www.hackingwithswift.com)

Controlroom是一个神奇的应用程序,我最近遇到了,它允许控制模拟器。它提供了一个很好的UI来定制通知。特别感谢Paul Hudson在git.Git URL中分享源代码。https:/github.comtwostrawsControlRoom。

enter image description here

选项2 - 使用终端

在终端上运行以下命令

   xcrun simctl push <simulator identifier> <bundle identifier of the app> <pushcontentfile>.apns"

如何使用Xcode获取模拟器标识符?

Xcode Menu => Window => Devices and Simulators

enter image description here

.apns文件的格式

  • 将推送通知的有效载荷(json格式)保存到扩展名为".apns "的文件中。

    {
        "aps": {
            "alert": "Push Notifications Test",
            "sound": "default",
            "badge": 1
        }
    }

选项3--将.apns文件拖放到模拟器上。

.apns文件应该包含应用程序的捆绑标识符,作为有效载荷的一部分。


    {
      "Simulator Target Bundle": "<bundle identifier of the app>",
      "aps": {
        "alert": "Push Notifications Test",
        "sound": "default",
        "badge": 1
      }
    }

© www.soinside.com 2019 - 2024. All rights reserved.