我想用推送通知来UI测试我的应用程序,也许有些人已经找到了最佳实践。有很多教程和问题,但我无法找到令人满意的答案。
- 开始测试
- 发送推送通知
- 点击推送通知
- 执行任务
但是,发送推送通知的最佳实践是什么呢?
- Rest调用触发推送通知
- 获取终端访问权限(但如何?)并运行:
xcrun simctl push <device> com.example.my-app ExamplePush.apns
- 发送本地推送通知?
- 模拟服务器
- 使用类似于Mussel的框架
谢谢!:)
gem install houston
如果您遇到以下错误:
Fetching houston-2.4.0.gem ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
首先在终端中运行以下命令安装Ruby:
brew install ruby
export GEM_HOME="$HOME/.gem"
gem install rails
成功安装后再运行一次:
gem install houston
进入pem文件夹,并在该文件夹中打开终端。
运行以下命令:
apn push "Device Token" -c PEM_FILE_NAME -m "MESSAGE"
例如:
apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_dev.pem -m "Testing"
下面是使用类别标识符触发本地通知的示例代码。
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)")
}
}
如果您想创建测试推送通知,则可以用于测试目的。
这个库非常有帮助。