Reputation: 2317
When uploading an app to the appStore, Apple checks if the Bundle Version is higher than the existing one. Is there an existing method for doing this myself? I'm releasing an app through an Enterprise program, and I have built-in a mechanism that checks a URL for a newer version. Currently I just use
if (![currentVersion isEqualToString:onlineVersion])
but that is too crude, because it also returns TRUE if there is an older version.
Now, realizing that 1.23.0 > 1.3.0, I would have to separate the version in components, and then compare each local component to it's related online one.
If I'll have to do that, I'll have to do that, but I would assume that there is a short cut for that.
Anyone?
Upvotes: 0
Views: 942
Reputation: 4678
Here's the apple way
updateAvailable = [newversion compare:currentversion options:NSNumericSearch] == NSOrderedDescending;
Upvotes: 5
Reputation: 2317
OK, OK, I ended up doing it all myself. Sorry for being so lazy. I hope though, that this will help somebody, or that someone will point out a blatant error, or stupid inefficiency:
- (BOOL) compareBundleVersions: (NSString *) old to: (NSString *) new {
NSMutableArray *oldArray = [[old componentsSeparatedByString:@"."] mutableCopy];
NSMutableArray *newArray = [[new componentsSeparatedByString:@"."] mutableCopy];
// Here I need to make sure that both arrays are of the same length, appending a zero to the shorter one
int q = [oldArray count] - [newArray count];
NSString *zero = @"0";
if (q>0) {
for (int i = 0; i < q; i++)
{
[newArray addObject:zero];
}
}
if (q<0) {
for (int i = 0; i < q*-1; i++)
{
[oldArray addObject:zero];
}
}
for (int i = 0; i < [oldArray count]; i++)
{
if ([[oldArray objectAtIndex:i] intValue] < [[newArray objectAtIndex:i] intValue]) {
return TRUE;
}
}
return FALSE;
}
Upvotes: 2