Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
private let kNotificationProberKey = "warning"

/// Timeout for probing whether the app delegate forwards the remote notification to us.
private let kProbingTimeout = 1.0
private let kProbingTimeout = 15.0

/// The application.
private let application: UIApplication
Expand Down Expand Up @@ -91,22 +91,33 @@
return isNotificationBeingForwarded
}
if await pendingCount.increment() == 1 {
DispatchQueue.main.async {
Task { @MainActor in
let proberNotification = [self.kNotificationDataKey: [self.kNotificationProberKey:
"This fake notification should be forwarded to Firebase Auth."]]
if let delegate = self.application.delegate,
delegate
.responds(to: #selector(UIApplicationDelegate
.application(_:didReceiveRemoteNotification:fetchCompletionHandler:))) {
delegate.application?(self.application,
didReceiveRemoteNotification: proberNotification) { _ in

var attempts = 0
var delegateFound = false

while attempts < 10 && !delegateFound {
if let delegate = self.application.delegate,
delegate.responds(
to: #selector(UIApplicationDelegate
.application(_:didReceiveRemoteNotification:fetchCompletionHandler:))
) {
delegate.application?(
self.application,
didReceiveRemoteNotification: proberNotification
) { _ in }
delegateFound = true
} else {
attempts += 1
try? await Task.sleep(nanoseconds: 300_000_000)
}
} else {
AuthLog.logWarning(
code: "I-AUT000015",
message: "The UIApplicationDelegate must handle " +
"remote notification for phone number authentication to work."
)
}

if !delegateFound {
self.isNotificationBeingForwarded = true
self.condition.signal()
}
kAuthGlobalWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(self.timeout))) {
self.condition.signal()
Expand Down