我想使用推送通知对我的应用程序进行 UI 测试,也许你们中的一些人已经找到了最佳实践。有很多教程和问题,但我找不到满意的答案。
- 开始测试
- 发送推送通知
- 点击推送通知
- 做事
但是发送推送通知的最佳做法是什么?
- 触发推送通知的Rest Call
- 获得对终端的访问权限(但如何?)并运行:
xcrun simctl push <device> com.example.my-app ExamplePush.apns
- 发送本地推送通知?
- 模拟服务器
- 使用类似Mussel 的框架
谢谢! :)
最佳答案
使用终端通过单行命令测试推送通知
在您的 Mac 中安装 Houston,在终端中运行以下命令。
gem 安装休斯顿
如果你遇到这样的错误,
正在获取 houston-2.4.0.gem 错误:执行 gem 时...(Gem::FilePermissionError) 您没有/Library/Ruby/Gems/2.6.0 目录的写入权限。
首先在终端运行下面的命令来安装Ruby
brew 安装 ruby
导出 GEM_HOME="$HOME/.gem"
gem 安装导轨
安装成功后再次运行
gem 安装休斯顿
转到 pem 文件文件夹并从该文件夹打开终端。
运行如下命令
apn push "设备 token "-c PEM_FILE_NAME -m "MESSAGE"
喜欢:
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9"-c myapp_apns_dev.pem -m "测试"
成功运行上述命令后,它会询问 PEM 密码,这是您的 pem 文件的密码。
如果您的应用已上线,则使用生产 pem 文件名
像这样,
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9"-c myapp_apns_pro.pem -m "测试"
完成。
对于 UI 测试,您可以使用本地通知,
您必须为本地通知设置 categoryIdentifier 并确保在您的 AppExtension Info.plist 文件中将相同的 categoryIdentifier 设置为 UNNotificationExtensionCategory
更多详情请引用以下链接
下面是使用类别标识符触发本地通知的示例代码
let content = UNMutableNotificationContent()
content.title = title
content.body = body
content.categoryIdentifier = "LOCAL_NOTIFICATION"
if let info = userInfo {
let dic = ["body" : "Custom Data"]
content.userInfo = dic as [AnyHashable : Any]
}
content.sound = UNNotificationSound.init(named: UNNotificationSoundName(rawValue: sound))
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: "LOCAL_NOTIFICATION", content: content, trigger: trigger)
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if let error = error {
print("Error \(error.localizedDescription)")
}
}
关于测试推送通知的 iOS 最佳实践(UI 测试),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66349457/