[英]How to disable push notifications prompt when running Flutter Driver tests
我使用 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部分設置了這個標志,用於運行 Flutter Driver 測試時默認使用的Debug-development
風格:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.