Skip to content
This repository has been archived by the owner on Nov 22, 2020. It is now read-only.

Commit

Permalink
Fixed retain cycle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtSabintsev committed Mar 8, 2018
1 parent a93b63d commit 679c656
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions Harpy/Harpy.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ - (void)checkVersionDaily {
Also, performs version check on first launch.
*/
if (![self lastVersionCheckPerformedOnDate]) {

// Set Initial Date
self.lastVersionCheckPerformedOnDate = [NSDate date];

// Perform First Launch Check
[self checkVersion];
}

// If daily condition is satisfied, perform version check
if ([self numberOfDaysElapsedBetweenLastVersionCheckDate] >= 1) {
[self checkVersion];
Expand All @@ -137,15 +137,15 @@ - (void)checkVersionWeekly {
Also, performs version check on first launch.
*/
if (![self lastVersionCheckPerformedOnDate]) {

// Set Initial Date
self.lastVersionCheckPerformedOnDate = [NSDate date];

// Perform First Launch Check
[self checkVersion];
}
// If weekly condition is satisfied, perform version check

// If weekly condition is satisfied, perform version check
if ([self numberOfDaysElapsedBetweenLastVersionCheckDate] >= 7) {
[self checkVersion];
}
Expand Down Expand Up @@ -175,10 +175,13 @@ - (void)parseResults:(NSData *)data {
[self printDebugMessage:[NSString stringWithFormat:@"JSON Results: %@", _appData]];

if ([self isUpdateCompatibleWithDeviceOS:_appData]) {

__typeof__(self) __weak weakSelf = self;

dispatch_async(dispatch_get_main_queue(), ^{

// Store version comparison date
self.lastVersionCheckPerformedOnDate = [NSDate date];
weakSelf.lastVersionCheckPerformedOnDate = [NSDate date];
[[NSUserDefaults standardUserDefaults] setObject:[self lastVersionCheckPerformedOnDate] forKey:HarpyDefaultStoredVersionCheckDate];
[[NSUserDefaults standardUserDefaults] synchronize];

Expand All @@ -194,9 +197,9 @@ the user will prompted to update their app (if the version is newer - checked la
if (releaseDateString == nil) {
return;
} else {
NSInteger daysSinceRelease = [self daysSinceDateString:releaseDateString];
if (!(daysSinceRelease >= _showAlertAfterCurrentVersionHasBeenReleasedForDays)) {
NSString *message = [NSString stringWithFormat:@"Your app has been released for %ld days, but Siren cannot prompt the user until %lu days have passed.", (long)daysSinceRelease, (unsigned long)_showAlertAfterCurrentVersionHasBeenReleasedForDays];
NSInteger daysSinceRelease = [weakSelf daysSinceDateString:releaseDateString];
if (!(daysSinceRelease >= weakSelf.showAlertAfterCurrentVersionHasBeenReleasedForDays)) {
NSString *message = [NSString stringWithFormat:@"Your app has been released for %ld days, but Siren cannot prompt the user until %lu days have passed.", (long)daysSinceRelease, (unsigned long)weakSelf.showAlertAfterCurrentVersionHasBeenReleasedForDays];
[self printDebugMessage:message];
return;
}
Expand All @@ -213,9 +216,9 @@ the user will prompted to update their app (if the version is newer - checked la
return;
} else {
if ([versionsInAppStore count]) {
_currentAppStoreVersion = [versionsInAppStore objectAtIndex:0];
if ([self isAppStoreVersionNewer:_currentAppStoreVersion]) {
[self appStoreVersionIsNewer:_currentAppStoreVersion];
weakSelf.currentAppStoreVersion = [versionsInAppStore objectAtIndex:0];
if ([weakSelf isAppStoreVersionNewer:weakSelf.currentAppStoreVersion]) {
[weakSelf appStoreVersionIsNewer:weakSelf.currentAppStoreVersion];
} else {
[self printDebugMessage:@"Currently installed version is newer."];
}
Expand Down Expand Up @@ -255,7 +258,7 @@ - (BOOL)isUpdateCompatibleWithDeviceOS:(NSDictionary<NSString *, id> *)appData {
if (
([systemVersion compare:requiresOSVersion options:NSNumericSearch] == NSOrderedDescending) ||
([systemVersion compare:requiresOSVersion options:NSNumericSearch] == NSOrderedSame)
) {
) {
return true;
} else {
return false;
Expand Down Expand Up @@ -287,7 +290,7 @@ - (BOOL)isAppStoreVersionNewer:(NSString *)currentAppStoreVersion {
}

- (void)appStoreVersionIsNewer:(NSString *)currentAppStoreVersion {
_appID = _appData[@"results"][0][@"trackId"];
_appID = _appData[@"results"][0][@"trackId"];

if (_appID == nil) {
[self printDebugMessage:@"appID is nil, which means to the trackId key is missing from the JSON results that Apple returned for your bundleID. If a version of your app is in the store and you are seeing this message, please open up an issue http://github.com/ArtSabintsev/Harpy and provide as much detail about your app as you can. Thanks!"];
Expand Down Expand Up @@ -479,7 +482,7 @@ - (UIAlertAction *)updateAlertAction {
handler:^(UIAlertAction *action) {
[self launchAppStore];
}];

return updateAlertAction;
}

Expand All @@ -491,21 +494,23 @@ - (UIAlertAction *)nextTimeAlertAction {
[self.delegate harpyUserDidCancel];
}
}];

return nextTimeAlertAction;
}

- (UIAlertAction *)skipAlertAction {
__typeof__(self) __weak weakSelf = self;

UIAlertAction *skipAlertAction = [UIAlertAction actionWithTitle:_skipButtonText
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[[NSUserDefaults standardUserDefaults] setObject:_currentAppStoreVersion forKey:HarpyDefaultSkippedVersion];
[[NSUserDefaults standardUserDefaults] setObject:weakSelf.currentAppStoreVersion forKey:HarpyDefaultSkippedVersion];
[[NSUserDefaults standardUserDefaults] synchronize];
if([self.delegate respondsToSelector:@selector(harpyUserDidSkipVersion)]){
[self.delegate harpyUserDidSkipVersion];
}
}];

return skipAlertAction;
}

Expand Down

0 comments on commit 679c656

Please sign in to comment.