我正在计划更新一款企业应用,需要进行ad-hoc分发。
对于更新,苹果公司建议用户访问一个HTML页面并点击链接:
href="itms-services://?action=download-manifest&url=http://example.com/
manifest.plist"
请参考http://help.apple.com/iosdeployment-apps/#app43ad871e
我不想这样做。我希望应用程序在启动时以编程方式检查更新,并使用UIAlertView向用户发出提示,表示有可用的更新。
在didFinishLaunching中,我已经实现了以下内容。复杂的plist解析来自于此处找到的示例plist的结构: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]];
}
}
有几个问题:
- 我知道 [alert show] 不应该在 application didFinish 中被调用,但我会稍后更改它。
- 我不知道 plistData 将被下载多快以及这种下载如何影响应用程序。
- 更重要的是,我的警报视图委托方法不起作用,并且更新没有下载。即使我使用 @property (nonatomic, strong) UIWebView *webView 引入 webView,该方法也没有做任何事情。
- 我认为 Dropbox 已经正确配置了 MIME,因为我可以通过 google Chrome 下载 .ipa。
所以我真正需要的是一个使用 NSURLConnection(NSURLRequest 等)的方法来复制用户点击 HTML href 的行为。之后我认为完整的更新将发生。