ios - 运行 Flutter Driver 测试时如何禁用推送通知提示
问题描述
我使用 Flutter Driver 运行我的 e2e 测试。我使用的典型命令是:
flutter drive --flavor=development --target=e2e/instrumented_app.dart --driver=e2e/scenarios/smoke_scenario.dart -d "iPhone 11"
但是,在添加推送通知支持后,我的测试在启动时超时,因为显示了推送通知提示。运行 Flutter Driver 测试时如何授予访问权限或跳过提示?
解决方案
我想出的是使用 Swift 自定义标志
在我的 AppDelegate 中,didFinishLaunchingWithOptions
我使用了条件标志SKIP_NOTIFICATIONS_PROMPT
:
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let brazeApiKey = ""
Appboy.start(withApiKey: brazeApiKey as! String, in:application, withLaunchOptions:launchOptions)
if #available(iOS 10, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self as UNUserNotificationCenterDelegate
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
#if SKIP_NOTIFICATIONS_PROMPT
// skipping permission request for uat test builds
#else
center.requestAuthorization(options: options) { (granted, error) in
Appboy.sharedInstance()?.pushAuthorization(fromUserNotificationCenter: granted)
}
#endif
UIApplication.shared.registerForRemoteNotifications()
} else {
let types : UIUserNotificationType = [.alert, .badge, .sound]
let setting : UIUserNotificationSettings = UIUserNotificationSettings(types:types, categories:nil)
UIApplication.shared.registerUserNotificationSettings(setting)
UIApplication.shared.registerForRemoteNotifications()
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
我在项目的 Build Settings 的Other Swift Flags部分设置了这个标志,Debug-development
用于运行 Flutter Driver 测试时默认使用的风格:
推荐阅读
- wordpress - 如何覆盖 woocommerce_download_file_redirect 函数?
- excel - Sumifs或索引匹配?
- javascript - 如何创建具有给定键和值的对象?
- php - PhpOffice 将 excel 转换为 json
- java - 针对不同用户的设计模式
- api - 使用 GCP API 网关的 Graphql 后端的 OpenAPI 配置?
- google-apps-script - 有没有我可以创建的谷歌脚本,所以我的电子表格中的每一行都会复制到一个新的单独的工作表中?
- python - 给出响应后如何继续执行函数?
- visual-studio - 在调试会话之间单独保留选项卡 (Visual Studio 2019)
- javascript - Puppeteer:转到页码