diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index bcc9b9680..e29bba3ec 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -7869,7 +7869,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; COMPILE_LIB_SESSION = ""; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -7908,7 +7908,7 @@ HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include/**"; IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-Werror=protocol"; OTHER_SWIFT_FLAGS = "-D DEBUG -Xfrontend -warn-long-expression-type-checking=100"; @@ -7947,7 +7947,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; COMPILE_LIB_SESSION = ""; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_MODULE_VERIFIER = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -7982,7 +7982,7 @@ HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include/**"; IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1", @@ -8495,7 +8495,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; COMPILE_LIB_SESSION = YES; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -8536,7 +8536,7 @@ ); IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = ( "-fobjc-arc-exceptions", @@ -9165,7 +9165,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; COMPILE_LIB_SESSION = YES; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_NO_COMMON_BLOCKS = YES; @@ -9201,7 +9201,7 @@ ); IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1", diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index eed100801..3bcee7a69 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -329,9 +329,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD /// /// Additionally we want to ensure that our timeout timer has enough time to run so make sure we have at least `5 seconds` /// of background execution (if we don't then the process could incorrectly run longer than it should) + let remainingTime: TimeInterval = application.backgroundTimeRemaining + guard - application.backgroundTimeRemaining < TimeInterval.greatestFiniteMagnitude && - application.backgroundTimeRemaining > 5 + remainingTime != TimeInterval.nan && + remainingTime < TimeInterval.greatestFiniteMagnitude && + remainingTime > 5 else { return completionHandler(.failed) } Log.appResumedExecution() @@ -349,7 +352,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD /// /// **Note:** We **MUST** capture both `poller` and `cancellable` strongly in the event handler to ensure neither /// go out of scope until we want them to (we essentually want a retain cycle in this case) - let durationRemainingMs: Int = max(1, Int((application.backgroundTimeRemaining - 5) * 1000)) + let durationRemainingMs: Int = max(1, Int((remainingTime - 5) * 1000)) let timer: DispatchSourceTimer = DispatchSource.makeTimerSource(queue: queue) timer.schedule(deadline: .now() + .milliseconds(durationRemainingMs)) timer.setEventHandler { [poller, dependencies] in diff --git a/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift b/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift index 8f82aa7dd..e28083e94 100644 --- a/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift +++ b/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift @@ -608,15 +608,8 @@ public extension LibSession { // Only generate the push data if we need to do a push guard config.needsPush else { return } - guard let data: PendingChanges.PushData = config.push(variant: info.variant) else { - throw LibSessionError( - config, - fallbackError: .unableToGeneratePushData, - logMessage: "Failed to generate push data for \(info.variant) config data, size: \(config.countDescription), error" - ) - } - - result.append(data: data) + // Try to generate the push data (will throw if there is an error) + try result.append(data: config.push(variant: info.variant)) } } diff --git a/SessionMessagingKit/LibSession/Types/Config.swift b/SessionMessagingKit/LibSession/Types/Config.swift index 2786adf11..b9ee340d9 100644 --- a/SessionMessagingKit/LibSession/Types/Config.swift +++ b/SessionMessagingKit/LibSession/Types/Config.swift @@ -124,12 +124,22 @@ public extension LibSession { // MARK: - Functions - func push(variant: ConfigDump.Variant) -> PendingChanges.PushData? { + func push(variant: ConfigDump.Variant) throws -> PendingChanges.PushData? { switch self { case .userProfile(let conf), .contacts(let conf), .convoInfoVolatile(let conf), .userGroups(let conf), .groupInfo(let conf), .groupMembers(let conf): - let cPushData: UnsafeMutablePointer = config_push(conf) + /// The `config_push` function implicitly unwraps it's value but can throw internally so call it in a guard + /// statement to prevent the implicit unwrap from causing a crash (ideally it would return a standard optional + /// so the compiler would warn us but it's not that straight forward when dealing with C) + guard let cPushData: UnsafeMutablePointer = config_push(conf) else { + throw LibSessionError( + self, + fallbackError: .unableToGeneratePushData, + logMessage: "Failed to generate push data for \(variant) config data, size: \(countDescription), error" + ) + } + let pushData: Data = Data( bytes: cPushData.pointee.config, count: cPushData.pointee.config_len