Привет всем, в будущем я нашел этот урок, который должен помочь всем, он мне помог.
http://codewithchris.com/tutorial-how-to-implement-in-app-update-functionality-in-your-iphoneipad-app/
Изменить (ваш код будет выглядеть примерно так, как показано ниже):
// Try to get version
NSString *versionNumber = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSURL *updateUrl = [NSURL URLWithString:@"http://yourdomain.com/yourupdatefile.xml"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:updateUrl
cachePolicy:NSURLCacheStorageNotAllowed
timeoutInterval:20.0];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
// Check no error, then parse data
if (error == nil)
{
// Parse response into a dictionary
NSPropertyListFormat format;
NSString *errorStr = nil;
NSDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&errorStr];
if (errorStr == nil)
{
@try {
// Try to see if the current app version exists in the update xml
NSString *itunesUrl = [dictionary objectForKey:versionNumber];
if (itunesUrl)
{
// Show dialog to ask user to update!
}
else {
// Version not in XML
}
} @catch (NSException *e) {
// Error with retrieving the key
}
}
else {
// Error with parsing data into dictionary
}
}
Однако после дальнейших исследований я обнаружил, что это отличное решение, если вы не используете сервер.
-(BOOL) needsUpdate{
NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([lookup[@"resultCount"] integerValue] == 1){
NSString* appStoreVersion = lookup[@"results"][0][@"version"];
NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
if (![appStoreVersion isEqualToString:currentVersion]){
NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
return YES;
}
}
return NO;
}
В:
if (![appStoreVersion isEqualToString:currentVersion]){
NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
return YES;
}
Часть кода, который вы задаете, что вы хотите сделать, если он не равен, здесь вы отправляете пользователя в магазин приложений, чтобы загрузить последнюю версию.