我正在计划通过临时分发对企业应用进行更新。
对于更新,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 委托(delegate)方法:
- (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 的下载速度有多快以及这种下载对应用有何影响。
- 更重要的是,我的警报 View 委托(delegate)方法不起作用,更新也不会下载。即使当我使用 @property (nonatomic, strong) UIWebView *webView 引入 webView 时,该方法也没有做任何事情。
- 我认为 Dropbox 的 MIME 配置正确,因为我可以通过谷歌浏览器下载 .ipa。
所以我真正需要的是使用 NSURLConnection(NSURLRequest 等)复制用户点击 HTML href 的行为。之后我认为会进行全面更新。
最佳答案
您可以使用自动打开 URL
[[UIApplication sharedApplication] openURL:...];
我不知道它是否适用于 itms-services: urls,但它适用于其他定制的 URL 方案,如 tel:、fb: 等。所以它应该可以,除非 Apple 明确阻止它。
关于iphone - 以编程方式点击 HTML href 以更新应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136139/