Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Installations access on background queue #14227

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Fixed an issue where Installations was sometimes invoked off the main queue (#13961).

# 11.5.0
- [changed] Updated `upload-symbols` to version 3.19, removed all methods require CFRelease and switch to modern classes (#13420).

Expand Down
3 changes: 3 additions & 0 deletions FirebasePerformance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Fixed an issue where Installations was sometimes invoked off the main queue (#13961).

# 11.6.0
- [fixed] Fix a crash related to registering for notifications when the app is between foreground or background states. (#13174)

Expand Down
40 changes: 22 additions & 18 deletions FirebaseSessions/Sources/Settings/SettingsDownloadClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,31 @@ class SettingsDownloader: SettingsDownloadClient {
return
}

installations.installationID { result in
switch result {
case let .success(installationsInfo):
let request = self.buildRequest(url: validURL, fiid: installationsInfo.0)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data {
if let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
completion(.success(dict))
} else {
completion(.failure(
.JSONParseError("Failed to parse JSON to dictionary")
))
DispatchQueue.main.async {
// Installation's FIRInstallationsIDController isn't thread-safe, so this has to go
// on the main thread.
self.installations.installationID { result in
switch result {
case let .success(installationsInfo):
let request = self.buildRequest(url: validURL, fiid: installationsInfo.0)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data {
if let dict = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
completion(.success(dict))
} else {
completion(.failure(
.JSONParseError("Failed to parse JSON to dictionary")
))
}
} else if let error {
completion(.failure(.URLSessionError(error.localizedDescription)))
}
} else if let error {
completion(.failure(.URLSessionError(error.localizedDescription)))
}
// Start the task that sends the network request
task.resume()
case let .failure(error):
completion(.failure(.InstallationIDError(error.localizedDescription)))
}
// Start the task that sends the network request
task.resume()
case let .failure(error):
completion(.failure(.InstallationIDError(error.localizedDescription)))
}
}
}
Expand Down
Loading