iGriever/TWSReleaseNotesView

Flawed Logic

Closed this issue · 3 comments

+ (BOOL)isAppVersionUpdated checks for a NSUserDefaultsentry with the key kTWSReleaseNotesViewVersionKey and stores it in an iVar named previousAppVersion. If is is not found, previousAppVersion will be nil, and the conditionResult will consequently be NO because it tests for presence of this string.

In versionStatusWithConditionResult you only set the value for this key if condition result is YES, meaning that the NSUserDefaults entry for kTWSReleaseNotesViewVersionKey will NEVER get set.

I know you want to have people use the chained check of ![TWSReleaseNotesView isAppOnFirstLaunch] && [TWSReleaseNotesView isAppVersionUpdated] to determine whether to show it. In this case, it works correctly, but if you are going to have separate publicly accessible functions, you need to make sure they both work as intended independently of each other, or combine them into a single check.

Correct. I modified the two implementations in the following way, it should fix the logic in both cases. The versionStatusWithConditionResult method was removed:

+ (BOOL)isAppVersionUpdated
{
    // Read stored version string and current version string
    NSString *previousAppVersion = [[NSUserDefaults standardUserDefaults] stringForKey:kTWSReleaseNotesViewVersionKey];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];

    // Flag app as updated if a previous version string is found and it does not match with the current version string
    BOOL isUpdated = (previousAppVersion && ![previousAppVersion isEqualToString:currentAppVersion]) ? YES : NO;

    if (isUpdated || !previousAppVersion)
    {
        // Store current app version if needed
        [self storeCurrentAppVersionString];
    }

    return isUpdated;
}

+ (BOOL)isAppOnFirstLaunch
{
    // Read stored version string
    NSString *previousAppVersion = [[NSUserDefaults standardUserDefaults] stringForKey:kTWSReleaseNotesViewVersionKey];

    // Flag app as on first launch if no previous app string is found
    BOOL isFirstLaunch = (!previousAppVersion) ? YES : NO;

    if (isFirstLaunch)
    {
        // Store current app version if needed
        [self storeCurrentAppVersionString];
    }

    return isFirstLaunch;
}

+ (void)storeCurrentAppVersionString
{
    // Store current app version string in the user defaults
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
    [[NSUserDefaults standardUserDefaults] setObject:currentAppVersion forKey:kTWSReleaseNotesViewVersionKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

Submitted a pull request for pod version 1.1.1.

Fixed in pod version 1.1.1.