diff --git a/Signal/src/ViewControllers/HomeViewController.m b/Signal/src/ViewControllers/HomeViewController.m index 9d5d90744..543df0906 100644 --- a/Signal/src/ViewControllers/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeViewController.m @@ -560,6 +560,8 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; }]; } else if (!self.hasBeenPresented && [ProfileViewController shouldDisplayProfileViewOnLaunch]) { [ProfileViewController presentForUpgradeOrNag:self]; + } else { + [OWSAlerts showIOSUpgradeNagIfNecessary]; } self.hasBeenPresented = YES; diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index 2b45d83bc..ada15b621 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "NewContactThreadViewController.h" @@ -278,35 +278,7 @@ NS_ASSUME_NONNULL_BEGIN { [super viewDidAppear:animated]; - [self showIOSUpgradeNagIfNecessary]; -} - -- (void)showIOSUpgradeNagIfNecessary -{ - // Only show the nag to iOS 8 users. - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(9, 0)) { - return; - } - - // Don't show the nag to users who have just launched - // the app for the first time. - if (![AppVersion instance].lastAppVersion) { - return; - } - - // Only show the nag once per update of the app. - NSString *currentAppVersion = [AppVersion instance].currentAppVersion; - OWSAssert(currentAppVersion.length > 0); - NSString *lastNagAppVersion = [Environment.preferences iOSUpgradeNagVersion]; - if (lastNagAppVersion && ![lastNagAppVersion isEqualToString:currentAppVersion]) { - - [Environment.preferences setIOSUpgradeNagVersion:currentAppVersion]; - - [OWSAlerts showAlertWithTitle:NSLocalizedString(@"UPGRADE_IOS_ALERT_TITLE", - @"Title for the alert indicating that user should upgrade iOS.") - message:NSLocalizedString(@"UPGRADE_IOS_ALERT_MESSAGE", - @"Message for the alert indicating that user should upgrade iOS.")]; - } + [OWSAlerts showIOSUpgradeNagIfNecessary]; } #pragma mark - Table Contents diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 8c651c7e0..179977f4b 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1789,7 +1789,7 @@ "UPGRADE_EXPERIENCE_VIDEO_TITLE" = "Hello Secure Video Calls!"; /* Message for the alert indicating that user should upgrade iOS. */ -"UPGRADE_IOS_ALERT_MESSAGE" = "Signal will soon require iOS 9 or later. Please upgrade in Settings app >> General >> Software Update."; +"UPGRADE_IOS_ALERT_MESSAGE" = "Signal requires iOS 9 or later. Please upgrade iOS in Settings app >> General >> Software Update."; /* Title for the alert indicating that user should upgrade iOS. */ "UPGRADE_IOS_ALERT_TITLE" = "Upgrade iOS"; diff --git a/SignalMessaging/utils/OWSPreferences.h b/SignalMessaging/utils/OWSPreferences.h index 52cc7169c..d16febc7e 100644 --- a/SignalMessaging/utils/OWSPreferences.h +++ b/SignalMessaging/utils/OWSPreferences.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -58,8 +58,8 @@ extern NSString *const OWSPreferencesKeyEnableDebugLog; - (BOOL)hasDeclinedNoContactsView; - (void)setHasDeclinedNoContactsView:(BOOL)value; -- (void)setIOSUpgradeNagVersion:(NSString *)value; -- (nullable NSString *)iOSUpgradeNagVersion; +- (void)setIOSUpgradeNagDate:(NSDate *)value; +- (nullable NSDate *)iOSUpgradeNagDate; #pragma mark - Calling diff --git a/SignalMessaging/utils/OWSPreferences.m b/SignalMessaging/utils/OWSPreferences.m index 815a1e4ac..69f4e6c26 100644 --- a/SignalMessaging/utils/OWSPreferences.m +++ b/SignalMessaging/utils/OWSPreferences.m @@ -24,7 +24,7 @@ NSString *const OWSPreferencesKeyCallKitEnabled = @"CallKitEnabled"; NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled"; NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress"; NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView"; -NSString *const OWSPreferencesKeyIOSUpgradeNagVersion = @"iOSUpgradeNagVersion"; +NSString *const OWSPreferencesKeyIOSUpgradeNagDate = @"iOSUpgradeNagDate"; NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions_5"; NSString *const OWSPreferencesKey_IsRegistered = @"OWSPreferencesKey_IsRegistered"; @@ -179,14 +179,14 @@ NSString *const OWSPreferencesKey_IsRegistered = @"OWSPreferencesKey_IsRegistere [self setValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView toValue:@(value)]; } -- (void)setIOSUpgradeNagVersion:(NSString *)value +- (void)setIOSUpgradeNagDate:(NSDate *)value { - [self setValueForKey:OWSPreferencesKeyIOSUpgradeNagVersion toValue:value]; + [self setValueForKey:OWSPreferencesKeyIOSUpgradeNagDate toValue:value]; } -- (nullable NSString *)iOSUpgradeNagVersion +- (nullable NSDate *)iOSUpgradeNagDate { - return [self tryGetValueForKey:OWSPreferencesKeyIOSUpgradeNagVersion]; + return [self tryGetValueForKey:OWSPreferencesKeyIOSUpgradeNagDate]; } #pragma mark - Calling diff --git a/SignalMessaging/views/OWSAlerts.swift b/SignalMessaging/views/OWSAlerts.swift index a0d5cdf25..e66616791 100644 --- a/SignalMessaging/views/OWSAlerts.swift +++ b/SignalMessaging/views/OWSAlerts.swift @@ -65,4 +65,32 @@ import Foundation return action } + @objc + public class func showIOSUpgradeNagIfNecessary() { + // Only show the nag to iOS 8 users. + if #available(iOS 9.0, *) { + return + } + + // Don't show the nag to users who have just launched + // the app for the first time. + guard AppVersion.instance().lastAppVersion != nil else { + return + } + + if let iOSUpgradeNagDate = Environment.preferences().iOSUpgradeNagDate() { + // Nag no more than once every three days. + let kNagFrequencySeconds = 3 * kDayInterval + guard fabs(iOSUpgradeNagDate.timeIntervalSinceNow) > kNagFrequencySeconds else { + return + } + } + + Environment.preferences().setIOSUpgradeNagDate(Date()) + + OWSAlerts.showAlert(withTitle:NSLocalizedString("UPGRADE_IOS_ALERT_TITLE", + comment:"Title for the alert indicating that user should upgrade iOS."), + message:NSLocalizedString("UPGRADE_IOS_ALERT_MESSAGE", + comment:"Message for the alert indicating that user should upgrade iOS.")) + } } diff --git a/SignalServiceKit/src/Account/TSPreKeyManager.m b/SignalServiceKit/src/Account/TSPreKeyManager.m index 9078842f3..c76239637 100644 --- a/SignalServiceKit/src/Account/TSPreKeyManager.m +++ b/SignalServiceKit/src/Account/TSPreKeyManager.m @@ -15,17 +15,17 @@ // Time before deletion of signed prekeys (measured in seconds) // // Currently we retain signed prekeys for at least 7 days. -static const NSTimeInterval kSignedPreKeysDeletionTime = 7 * kDayInterval; +#define kSignedPreKeysDeletionTime ((NSTimeInterval)7 * kDayInterval) // Time before rotation of signed prekeys (measured in seconds) // // Currently we rotate signed prekeys every 2 days (48 hours). -static const NSTimeInterval kSignedPreKeyRotationTime = 2 * kDayInterval; +#define kSignedPreKeyRotationTime ((NSTimeInterval)7 * kDayInterval) // How often we check prekey state on app activation. // // Currently we check prekey state every 12 hours. -static const NSTimeInterval kPreKeyCheckFrequencySeconds = 12 * kHourInterval; +#define kPreKeyCheckFrequencySeconds ((NSTimeInterval)12 * kHourInterval) // We generate 100 one-time prekeys at a time. We should replenish // whenever ~2/3 of them have been consumed. @@ -42,7 +42,7 @@ static const NSUInteger kMaxPrekeyUpdateFailureCount = 5; // before the message sending is disabled. // // Current value is 10 days (240 hours). -static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 * kDayInterval; +#define kSignedPreKeyUpdateFailureMaxFailureDuration ((NSTimeInterval)10 * kDayInterval) #pragma mark - diff --git a/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.h b/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.h index 1aa20daab..1f3add501 100644 --- a/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.h +++ b/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN -extern const uint32_t OWSDisappearingMessagesConfigurationDefaultExpirationDuration; +#define OWSDisappearingMessagesConfigurationDefaultExpirationDuration kDayInterval @interface OWSDisappearingMessagesConfiguration : TSYapDatabaseObject diff --git a/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.m b/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.m index 6ea20514b..ba3583497 100644 --- a/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.m +++ b/SignalServiceKit/src/Contacts/OWSDisappearingMessagesConfiguration.m @@ -7,9 +7,6 @@ NS_ASSUME_NONNULL_BEGIN -// 1 day. -const uint32_t OWSDisappearingMessagesConfigurationDefaultExpirationDuration = kDayInterval; - @interface OWSDisappearingMessagesConfiguration () // Transient record lifecycle attributes. diff --git a/SignalServiceKit/src/Util/NSDate+OWS.h b/SignalServiceKit/src/Util/NSDate+OWS.h index eb10dfa38..a2bf304ee 100755 --- a/SignalServiceKit/src/Util/NSDate+OWS.h +++ b/SignalServiceKit/src/Util/NSDate+OWS.h @@ -5,11 +5,11 @@ NS_ASSUME_NONNULL_BEGIN // These NSTimeInterval constants provide simplified durations for readability. -#define kMinuteInterval 60 -#define kHourInterval (60 * kMinuteInterval) -#define kDayInterval (24 * kHourInterval) -#define kWeekInterval (7 * kDayInterval) -#define kMonthInterval (30 * kDayInterval) +extern const NSTimeInterval kMinuteInterval; +extern const NSTimeInterval kHourInterval; +extern const NSTimeInterval kDayInterval; +extern const NSTimeInterval kWeekInterval; +extern const NSTimeInterval kMonthInterval; #define kSecondInMs 1000 #define kMinuteInMs (kSecondInMs * 60) diff --git a/SignalServiceKit/src/Util/NSDate+OWS.mm b/SignalServiceKit/src/Util/NSDate+OWS.mm index 2d3e9a55d..80ace347b 100644 --- a/SignalServiceKit/src/Util/NSDate+OWS.mm +++ b/SignalServiceKit/src/Util/NSDate+OWS.mm @@ -7,6 +7,12 @@ NS_ASSUME_NONNULL_BEGIN +const NSTimeInterval kMinuteInterval = 60; +const NSTimeInterval kHourInterval = 60 * kMinuteInterval; +const NSTimeInterval kDayInterval = 24 * kHourInterval; +const NSTimeInterval kWeekInterval = 7 * kDayInterval; +const NSTimeInterval kMonthInterval = 30 * kDayInterval; + @implementation NSDate (OWS) + (uint64_t)ows_millisecondTimeStamp