【发布时间】:2012-02-03 22:05:48
【问题描述】:
我正在计划更新具有临时分发的企业应用程序。
对于更新,Apple 建议让用户访问 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]];
}
}
一些事情:
- 我知道不应该在应用程序 didFinish 中调用 [alert show],但我稍后会更改它。
- 我不知道下载 plistData 的速度有多快,以及此下载对应用程序有何影响。
- 更重要的是,我的警报视图委托方法不起作用,并且无法下载更新。即使我用@property (nonatomic, strong) UIWebView *webView 引入 webView,该方法也没有做任何事情。
- 我认为 Dropbox 的 MIME 配置正确,因为我可以通过 google Chrome 下载 .ipa。
所以我真正需要的是一种使用 NSURLConnection(NSURLRequest 等)来复制用户点击 HTML href 的行为的方法。在那之后,我认为会发生完整的更新。
【问题讨论】: