使用Xcode命令行工具给模拟器推送通知

532 阅读1分钟

Xcode命令行工具允许您从终端使用模拟器。
您可以启动模拟器、触发通用链接等。
其中一项命令允许您向 iOS 模拟器发送推送通知:

$ xcrun simctl push --help
Send a simulated push notification
Usage: simctl push <device> [<bundle identifier>] (<json file> | -)

        bundle identifier
             The bundle identifier of the target application
             If the payload file contains a 'Simulator Target Bundle' top-level key this parameter may be omitted.
             If both are provided this argument will override the value from the payload.
        json file
             Path to a JSON payload or '-' to read from stdin. The payload must:
               - Contain an object at the top level.
               - Contain an 'aps' key with valid Apple Push Notification values.
               - Be 4096 bytes or less.

Only application remote push notifications are supported. VoIP, Complication, File Provider, and other types are not supported.

该命令要求您传递几个参数:

  • <device> Simply set this to booted to use the open simulator. You can also use a device identifier which you could get with the xcrun simctl list devices | grep Booted command.
  • <bundle identifier> 将此设置为要测试推送通知的应用程序的捆绑标识符。
  • <json file> 这应该指向磁盘上包含推送通知详细信息的JSON文件。您还可以使用stdin提供JSON内容。 执行示例如下:
$ xcrun simctl push booted com.example.app payload.json 
Notification sent to 'com.example.app'