Я планирую обновления для корпоративного приложения с ad- одноразовое распространение.
Для получения обновлений Apple рекомендует пользователю посетить HTML-страницу и нажать на ссылку:
href="itms-services://?action=download-manifest&url=http://example.com/
manifest.plist"
См. http://help.apple.com/iosdeployment-apps/#app43ad871e
Я не хочу этого делать. Я хочу, чтобы приложение программно проверяло наличие обновлений при запуске и предупреждало пользователя с помощью UIAlertView о наличии обновления.
Вот что у меня есть в приложении didFinishLaunching. Сложный синтаксический анализ списков взято из структуры примера списка, найденного здесь: http://help.apple.com/iosdeployment-apps/#app43ad78b3
NSLog(@"checking for update");
NSData *plistData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://example.com/MyApp.plist"]];
if (plistData) {
NSLog(@"finished checking for update");
NSError *error;
NSPropertyListFormat format;
NSDictionary *plist = [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:&format error:&error];
if (plist) {
NSArray *items = [plist valueForKey:@"items"];
NSDictionary *dictionary;
if ([items count] > 0) {
dictionary = [items objectAtIndex:0];
}
NSDictionary *metaData = [dictionary objectForKey:@"metadata"];
float currentVersion = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue];
float newVersion = [[metaData objectForKey:@"bundle-version"] floatValue];
NSLog(@"newVersion: %f, currentVersion: %f", newVersion, currentVersion);
if (newVersion > currentVersion) {
NSLog(@"A new update is available");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Update available" message:@"A new update is available." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"UPDATE", nil];
[alert show];
}
}
}
Затем у меня есть метод делегата UIAlertView:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
NSLog(@"downloading full update");
UIWebView *webView = [[UIWebView alloc] init];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"itms-services://?action=download-manifest&url=http://example.com/MyApp.plist"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]];
}
}
Несколько вещей:
Итак, что мне действительно нужно, так это способ использования NSURLConnection (NSURLRequest и т. Д.) Для репликации действия пользователя, нажимающего href HTML . После этого думаю произойдет полное обновление.