以编程方式点击HTML href以更新应用

时间:2012-02-03 22:05:48

标签: iphone ios ipad adhoc

我正在计划使用临时分发的企业应用程序的更新。

对于更新,Apple建议让用户访问HTML页面并点击链接:

href="itms-services://?action=download-manifest&url=http://example.com/
manifest.plist"

请参阅http://help.apple.com/iosdeployment-apps/#app43ad871e

我不想这样做。我希望应用程序以编程方式检查启动时的更新,并使用UIAlertView向用户发出更新可用的警告。

这是我到目前为止在应用中所做的事.FinishLaunching。复杂的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]不应该在应用程序didFinish中调用,但我稍后会更改。
  • 我不知道下载plistData的速度有多快以及下载对应用程序的影响。
  • 更重要的是,我的警报视图委托方法不起作用,并且不会下载更新。即使我使用@property(非原子,强)UIWebView * webView引入webView,该方法也不会做任何事情。
  • 我认为Dropbox已正确配置MIME,因为我可以通过google Chrome下载.ipa。

所以我真正需要的是一种方式,使用NSURLConnection(NSURLRequest等)来复制用户点击HTML href 的行为。之后,我认为将进行全面更新。

1 个答案:

答案 0 :(得分:5)

您可以使用

自动打开网址
[[UIApplication sharedApplication] openURL:...];

我不知道它是否适用于itms-services:urls,但它适用于其他定制的URL方案,如tel:,fb:等,所以它应该做,除非Apple特别阻止它。