Seeing A LOT of crashes for this code which has been around for quite a while (on iOS 15). After a viewController that user has been using is dismissed we check some values to determine if we should prompt for a rating and write some values into NSUserDefaults and which is when the crash happens.
This code gets called when the user clicks a Done Button to dismiss the viewController:
-(void)dismissChart
{
[self.navigationController dismissViewControllerAnimated:YES completion:^{
if([IphemerisUtil okToRequestRatingUsingCount:OK_TO_REQUEST_REVIEW_COUNT])
[IphemerisUtil requestAppRating];
}];
}
This is what is called and where the crash occurs:
+(BOOL)okToRequestRatingUsingCount:(int)count
{
int curVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] intValue];
NSNumber *lastVerRated = [userSettings objectForKey:RateLastVersionRated];
int lastVersionRated = (lastVerRated != nil) ? [lastVerRated intValue] : 0;
NSNumber *ratePromptCnt = [userSettings objectForKey:RatePromptCounter];
int rateCounter = (ratePromptCnt != nil) ? [ratePromptCnt intValue] : 1;
NSDate *dateLastCounterIncrement = [userSettings objectForKey:RatePromptCounterLastDateIncrement];
if(!dateLastCounterIncrement) {
dateLastCounterIncrement = [NSDate date];
[userSettings setObject:dateLastCounterIncrement forKey:RatePromptCounterLastDateIncrement];
}
if(curVersion > lastVersionRated) {
if(rateCounter > count)
return YES;
else {
// Increment the counter only once a day
if([[NSDate date] timeIntervalSinceDate:dateLastCounterIncrement] > (3600 * 24)) {
rateCounter++;
[userSettings setObject:[NSNumber numberWithInt:rateCounter] forKey:RatePromptCounter];
}
}
}
return NO;
}
One of the two userSettings:setObject is crashing. As indicated by this symbolicated crash log for the above code.