【问题标题】:How to test PushNotification in IOS simulator Xcode如何在 IOS 模拟器 Xcode 中测试推送通知
【发布时间】:2020-09-03 10:36:05
【问题描述】:

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

【问题讨论】:

    标签: ios xcode apple-push-notifications ios-simulator


    【解决方案1】:

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

    为了测试,

    选项 1 - 使用 Paul Hudson(https://www.hackingwithswift.com/ 的作者)创建的“ControlRoom”Mac 应用程序

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

    选项 2 - 使用终端

    在终端中运行以下命令

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

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

    Xcode Menu => Window => Devices and Simulators
    

    .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
        }
    }
    

    【讨论】:

    • 很好的答案和选项?
    • 获取模拟器ID:xcrun simctl list | egrep '(Booted)'
    猜你喜欢
    • 2020-10-03
    • 2021-04-03
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多