前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS开发之模拟器测试远程推送

iOS开发之模拟器测试远程推送

作者头像
YungFan
发布2020-05-18 23:09:56
1.7K0
发布2020-05-18 23:09:56
举报
文章被收录于专栏:学海无涯学海无涯

Xcode 11.4 之前必须使用第三方和真机来测试远程推送(APNS)。 但 Xcode 11.4 之后可以通过simctl命令在模拟器上进行测试。

使用命令行

Xcode 命令行工具允许从终端上使用模拟器:启动模拟器,触发通用链接等。 其中有一个命令就是将远程推送通知发送到 iOS 模拟器。

查看帮助

代码语言:javascript
复制
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 :只需将其设置为booted即可使用已经启动的模拟器。 还可以使用xcrun simctl list devices | grep Booted查看已经启动的模拟器。
代码语言:javascript
复制
xcrun simctl list devices | grep Booted
    iPhone 11 Pro Max (97AE0B1F-4C63-4B02-906B-8B2CF9E3F4B0) (Booted)
  • bundle identifier:设置要测试远程推送的 App 的唯一标识符。
  • json file:包含远程推送通知详细内容的 JSON 文件。

案例

代码语言:javascript
复制
xcrun simctl push booted developer.yf.TestUIKit /Users/yangfan/Desktop/playload.json
playload.json
代码语言:javascript
复制
{
  "aps":{
    "alert":{
      "title":"测试",
      "subtitle":"远程推送",
      "body":"这是一条从远处而来的通知"
    },
    "sound":"default",
    "badge":1
  }
}

json结果

使用APNS文件

在 iOS 模拟器上测试远程推送通知的另一种方法是将 APNS 文件拖到 iOS 模拟器中。该文件后缀名为.apns,内容和上面的 JSON 文件差不多,但是添加了一个 Simulator Target Bundle ,描述唯一标识符。

代码语言:javascript
复制
{
  "Simulator Target Bundle": "developer.yf.TestUIKit",
  "aps":{
    "alert":{
      "title":"测试",
      "subtitle":"远程推送",
      "body":"这是一条从远处而来的通知"
    },
    "sound":"default",
    "badge":1
  }
}

apns结果.gif

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用命令行
    • 查看帮助
      • 案例
        • playload.json
    • 使用APNS文件
    相关产品与服务
    命令行工具
    腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档