Attempt to fix iOS 14 crash

This commit is contained in:
Kylmakalle 2025-05-06 01:02:58 +03:00
parent 64c904706b
commit 3c306ee71d
2 changed files with 37 additions and 8 deletions

View File

@ -65,43 +65,57 @@ public class SGLocalizationManager {
}
public func downloadLocale(_ locale: String) {
SGLogger.shared.log("DEBUG", "3.2")
#if DEBUG
SGLogger.shared.log("Strings", "DEBUG ignoring locale download: \(locale)")
if ({ return true }()) {
return
}
#endif
SGLogger.shared.log("DEBUG", "3.3")
let sanitizedLocale = self.sanitizeLocale(locale)
SGLogger.shared.log("DEBUG", "3.4")
guard let url = URL(string: self.getStringsUrl(for: sanitizedLocale)) else {
SGLogger.shared.log("Strings", "Invalid URL for locale: \(sanitizedLocale)")
return
}
SGLogger.shared.log("DEBUG", "3.5")
DispatchQueue.global(qos: .background).async {
SGLogger.shared.log("DEBUG", "3.6")
if let localeDict = NSDictionary(contentsOf: url) as? [String: String] {
SGLogger.shared.log("DEBUG", "3.7")
DispatchQueue.main.async {
SGLogger.shared.log("DEBUG", "3.8")
self.webLocalizations[sanitizedLocale] = localeDict
SGLogger.shared.log("DEBUG", "3.9")
SGLogger.shared.log("Strings", "Successfully downloaded locale \(sanitizedLocale)")
}
} else {
SGLogger.shared.log("DEBUG", "3.10")
SGLogger.shared.log("Strings", "Failed to download \(sanitizedLocale)")
}
}
}
private func sanitizeLocale(_ locale: String) -> String {
SGLogger.shared.log("DEBUG", "3.3.1")
var sanitizedLocale = locale
SGLogger.shared.log("DEBUG", "3.3.2")
let rawSuffix = "-raw"
SGLogger.shared.log("DEBUG", "3.3.3")
if locale.hasSuffix(rawSuffix) {
SGLogger.shared.log("DEBUG", "3.3.4")
sanitizedLocale = String(locale.dropLast(rawSuffix.count))
}
SGLogger.shared.log("DEBUG", "3.3.5")
if sanitizedLocale == "pt-br" {
SGLogger.shared.log("DEBUG", "3.3.6")
sanitizedLocale = "pt"
} else if sanitizedLocale == "nb" {
SGLogger.shared.log("DEBUG", "3.3.7")
sanitizedLocale = "no"
}
SGLogger.shared.log("DEBUG", "3.3.8")
return sanitizedLocale
}

View File

@ -1336,14 +1336,24 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
self.resetIntentsIfNeeded(context: context.context)
// MARK: Swiftgram
SGLogger.shared.log("DEBUG", "iOS \(UIDevice.current.systemVersion), APP \(Bundle.main.infoDictionary?[kCFBundleVersionKey as String] ?? "")")
SGLogger.shared.log("DEBUG", "1")
updateSGWebSettingsInteractivelly(context: context.context)
let _ = (context.context.sharedContext.presentationData.start(next: { presentationData in
SGLocalizationManager.shared.downloadLocale(presentationData.strings.baseLanguageCode)
}))
SGLogger.shared.log("DEBUG", "2")
let presentationData = context.context.sharedContext.currentPresentationData.with({ $0 })
SGLogger.shared.log("DEBUG", "3")
let baseLanguageCode = presentationData.strings.baseLanguageCode
SGLogger.shared.log("DEBUG", "3.1 baseLanguageCode \(baseLanguageCode)")
SGLocalizationManager.shared.downloadLocale(baseLanguageCode)
SGLogger.shared.log("DEBUG", "4")
if #available(iOS 13.0, *) {
SGLogger.shared.log("DEBUG", "5")
let _ = Task {
SGLogger.shared.log("DEBUG", "6")
let primaryContext = await self.getPrimaryContext(anyContext: context.context)
SGLogger.shared.log("DEBUG", "7")
SGLogger.shared.log("SGIAP", "Verifying Status \(primaryContext.sharedContext.immediateSGStatus.status) for: \(primaryContext.account.peerId.id._internalGetInt64Value())")
SGLogger.shared.log("DEBUG", "8")
let _ = await self.fetchSGStatus(primaryContext: primaryContext)
}
}
@ -3398,13 +3408,18 @@ extension AppDelegate {
SGLogger.shared.log("SGIAP", "Setting new primary user id: \(userId)")
SGSimpleSettings.shared.primaryUserId = stringUserId
}
} else {
SGLogger.shared.log("SGIAP", "Status expired")
DispatchQueue.main.async {
NotificationCenter.default.post(name: .SGIAPHelperValidationErrorNotification, object: nil, userInfo: ["error": "PayWall.ValidationError.Expired"])
}
}
value.status = newStatus
} else {
SGLogger.shared.log("SGIAP", "Status \(value.status) for \(userId) hasn't changed")
if newStatus < 1 {
if newStatus < 2 {
DispatchQueue.main.async {
NotificationCenter.default.post(name: .SGIAPHelperValidationErrorNotification, object: nil, userInfo: ["error": "PayWall.ValidationError.Expired"])
NotificationCenter.default.post(name: .SGIAPHelperValidationErrorNotification, object: nil, userInfo: ["error": "PayWall.ValidationError.TryAgain"])
}
}
}