diff --git a/NotificationContent/NotificationViewController.swift b/NotificationContent/NotificationViewController.swift index 8789860340..96174f8b6b 100644 --- a/NotificationContent/NotificationViewController.swift +++ b/NotificationContent/NotificationViewController.swift @@ -66,10 +66,13 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi return } - let apiId: Int32 = BuildConfig.shared().apiId + let baseAppBundleId = String(appBundleIdentifier[.. Void) -> () -> Void { +func fetchImageWithAccount(buildConfig: BuildConfig, proxyConnection: AccountProxyConnection?, account: StoredAccountInfo, inputFileLocation: Api.InputFileLocation, datacenterId: Int32, completion: @escaping (Data?) -> Void) -> () -> Void { MTLogSetEnabled(true) MTLogSetLoggingFunction({ str, args in //let string = NSString(format: str! as NSString, args!) @@ -57,7 +57,7 @@ func fetchImageWithAccount(proxyConnection: AccountProxyConnection?, account: St var apiEnvironment = MTApiEnvironment() - apiEnvironment.apiId = BuildConfig.shared().apiId + apiEnvironment.apiId = buildConfig.apiId apiEnvironment.langPack = "ios" apiEnvironment.layer = NSNumber(value: Int(serialization.currentLayer())) apiEnvironment.disableUpdates = true diff --git a/NotificationService/NotificationService.swift b/NotificationService/NotificationService.swift index da3dcb0962..e775de192e 100644 --- a/NotificationService/NotificationService.swift +++ b/NotificationService/NotificationService.swift @@ -461,7 +461,16 @@ class NotificationService: UNNotificationServiceExtension { contentHandler(bestAttemptContent) } } else { - self.cancelFetch = fetchImageWithAccount(proxyConnection: accountInfos.proxy, account: account, inputFileLocation: inputFileLocation, datacenterId: datacenterId, completion: { [weak self] data in + let appBundleIdentifier = Bundle.main.bundleIdentifier! + guard let lastDotRange = appBundleIdentifier.range(of: ".", options: [.backwards]) else { + return + } + + let baseAppBundleId = String(appBundleIdentifier[.. mapToSignal { account -> Signal in if let account = account { switch account { diff --git a/Telegram-iOS/AppDelegate.swift b/Telegram-iOS/AppDelegate.swift index ec44e4b4ad..d28f404f8e 100644 --- a/Telegram-iOS/AppDelegate.swift +++ b/Telegram-iOS/AppDelegate.swift @@ -346,17 +346,19 @@ final class SharedApplicationContext { } #endif - let apiId: Int32 = BuildConfig.shared().apiId - let languagesCategory = "ios" - let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown" - let networkArguments = NetworkInitializationArguments(apiId: apiId, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManager.voipMaxLayer, appData: BuildConfig.shared().bundleData) - let baseAppBundleId = Bundle.main.bundleIdentifier! let appGroupName = "group.\(baseAppBundleId)" let maybeAppGroupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupName) + let buildConfig = BuildConfig(baseAppBundleId: baseAppBundleId) + + let apiId: Int32 = buildConfig.apiId + let languagesCategory = "ios" + + let networkArguments = NetworkInitializationArguments(apiId: apiId, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManager.voipMaxLayer, appData: buildConfig.bundleData) + guard let appGroupUrl = maybeAppGroupUrl else { UIAlertView(title: nil, message: "Error 2", delegate: nil, cancelButtonTitle: "OK").show() return true @@ -371,7 +373,7 @@ final class SharedApplicationContext { isDebugConfiguration = true } - if isDebugConfiguration || BuildConfig.shared().isInternalBuild { + if isDebugConfiguration || buildConfig.isInternalBuild { LoggingSettings.defaultSettings = LoggingSettings(logToFile: true, logToConsole: false, redactSensitiveData: true) } else { LoggingSettings.defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true) @@ -428,7 +430,7 @@ final class SharedApplicationContext { telegramUIDeclareEncodables() - GlobalExperimentalSettings.isAppStoreBuild = BuildConfig.shared().isAppStoreBuild + GlobalExperimentalSettings.isAppStoreBuild = buildConfig.isAppStoreBuild GlobalExperimentalSettings.enableFeed = false #if DEBUG @@ -444,7 +446,7 @@ final class SharedApplicationContext { initializeAccountManagement() - let applicationBindings = TelegramApplicationBindings(isMainApp: true, containerPath: appGroupUrl.path, appSpecificScheme: BuildConfig.shared().appSpecificUrlScheme, openUrl: { url in + let applicationBindings = TelegramApplicationBindings(isMainApp: true, containerPath: appGroupUrl.path, appSpecificScheme: buildConfig.appSpecificUrlScheme, openUrl: { url in var parsedUrl = URL(string: url) if let parsed = parsedUrl { if parsed.scheme == nil || parsed.scheme!.isEmpty { @@ -537,7 +539,7 @@ final class SharedApplicationContext { UIApplication.shared.openURL(url) } }, openAppStorePage: { - let appStoreId = BuildConfig.shared().appStoreId + let appStoreId = buildConfig.appStoreId if let url = URL(string: "itms-apps://itunes.apple.com/app/id\(appStoreId)") { UIApplication.shared.openURL(url) } @@ -936,7 +938,7 @@ final class SharedApplicationContext { |> deliverOnMainQueue |> map { accountAndSettings -> UnauthorizedApplicationContext? in return accountAndSettings.flatMap { account, limitsConfiguration, callListSettings, otherAccountPhoneNumbers in - return UnauthorizedApplicationContext(sharedContext: sharedApplicationContext.sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers) + return UnauthorizedApplicationContext(buildConfig: buildConfig, sharedContext: sharedApplicationContext.sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers) } } }) @@ -1157,7 +1159,7 @@ final class SharedApplicationContext { } }) - if let hockeyAppId = BuildConfig.shared().hockeyAppId, !hockeyAppId.isEmpty { + if let hockeyAppId = buildConfig.hockeyAppId, !hockeyAppId.isEmpty { BITHockeyManager.shared().configure(withIdentifier: hockeyAppId, delegate: self) BITHockeyManager.shared().crashManager.crashManagerStatus = .alwaysAsk BITHockeyManager.shared().start() diff --git a/Telegram-iOS/ApplicationContext.swift b/Telegram-iOS/ApplicationContext.swift index 673675bab7..36c03f83fe 100644 --- a/Telegram-iOS/ApplicationContext.swift +++ b/Telegram-iOS/ApplicationContext.swift @@ -21,12 +21,12 @@ final class UnauthorizedApplicationContext { let rootController: AuthorizationSequenceController - init(sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) { + init(buildConfig: BuildConfig, sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) { self.sharedContext = sharedContext self.account = account let presentationData = sharedContext.currentPresentationData.with { $0 } - self.rootController = AuthorizationSequenceController(sharedContext: sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers, strings: presentationData.strings, theme: presentationData.theme, openUrl: sharedContext.applicationBindings.openUrl, apiId: BuildConfig.shared().apiId, apiHash: BuildConfig.shared().apiHash) + self.rootController = AuthorizationSequenceController(sharedContext: sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers, strings: presentationData.strings, theme: presentationData.theme, openUrl: sharedContext.applicationBindings.openUrl, apiId: buildConfig.apiId, apiHash: buildConfig.apiHash) account.shouldBeServiceTaskMaster.set(sharedContext.applicationBindings.applicationInForeground |> map { value -> AccountServiceTaskMasterMode in if value { diff --git a/Telegram-iOS/BuildConfig.h b/Telegram-iOS/BuildConfig.h index b84fc13cfd..42e8cff123 100644 --- a/Telegram-iOS/BuildConfig.h +++ b/Telegram-iOS/BuildConfig.h @@ -9,7 +9,7 @@ @interface BuildConfig : NSObject -+ (instancetype _Nonnull)sharedBuildConfig; +- (instancetype _Nonnull)initWithBaseAppBundleId:(NSString * _Nonnull)baseAppBundleId; @property (nonatomic, strong, readonly) NSData * _Nullable bundleData; @property (nonatomic, strong, readonly) NSString * _Nullable hockeyAppId; diff --git a/Telegram-iOS/BuildConfig.m b/Telegram-iOS/BuildConfig.m index de6c59c690..89d85f576f 100644 --- a/Telegram-iOS/BuildConfig.m +++ b/Telegram-iOS/BuildConfig.m @@ -339,20 +339,18 @@ API_AVAILABLE(ios(10)) return instance; } -- (instancetype)init { +- (instancetype _Nonnull)initWithBaseAppBundleId:(NSString * _Nonnull)baseAppBundleId { self = [super init]; if (self != nil) { _apiId = APP_CONFIG_API_ID; _apiHash = @(APP_CONFIG_API_HASH); _hockeyAppId = @(APP_CONFIG_HOCKEYAPP_ID); - NSString *bundleId = [NSBundle mainBundle].bundleIdentifier; - MTPKCS *signature = checkSignature([[[NSBundle mainBundle] executablePath] UTF8String]); NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init]; - if (bundleId != nil) { - dataDict[@"bundleId"] = bundleId; + if (baseAppBundleId != nil) { + dataDict[@"bundleId"] = baseAppBundleId; } if (signature.name != nil) { dataDict[@"name"] = signature.name; diff --git a/Widget/TodayViewController.swift b/Widget/TodayViewController.swift index 2a3fa470cb..f80bf97b5c 100644 --- a/Widget/TodayViewController.swift +++ b/Widget/TodayViewController.swift @@ -27,6 +27,7 @@ class TodayViewController: UIViewController, NCWidgetProviding { private var initializedInterface = false private let disposable = MetaDisposable() + private var buildConfig: BuildConfig? deinit { self.disposable.dispose() @@ -53,11 +54,14 @@ class TodayViewController: UIViewController, NCWidgetProviding { guard let lastDotRange = appBundleIdentifier.range(of: ".", options: [.backwards]) else { return } + let baseAppBundleId = String(appBundleIdentifier[.. mapToSignal { account -> Signal in if let account = account { switch account { @@ -137,8 +141,8 @@ class TodayViewController: UIViewController, NCWidgetProviding { self.peerViews = [] for peer in peers { let peerView = PeerView(account: account, peer: peer, tapped: { [weak self] in - if let strongSelf = self { - if let url = URL(string: "\(BuildConfig.shared().appSpecificUrlScheme)://localpeer?id=\(peer.id.toInt64())") { + if let strongSelf = self, let buildConfig = strongSelf.buildConfig { + if let url = URL(string: "\(buildConfig.appSpecificUrlScheme)://localpeer?id=\(peer.id.toInt64())") { strongSelf.extensionContext?.open(url, completionHandler: nil) } }