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

Dav*_*aun 5 iphone adhoc ipad ios

我正在为具有临时分发的企业应用程序进行更新计划.

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

href="itms-services://?action=download-manifest&url=http://example.com/?manifest.plist"
Run Code Online (Sandbox Code Playgroud)

请参阅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];
        }       
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我有我的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]];
    }
}
Run Code Online (Sandbox Code Playgroud)

一些东西:

  • 我知道[alert show]不应该在应用程序didFinish中调用,但我稍后会更改它.
  • 我不知道下载plistData的速度有多快以及下载如何影响应用程序.
  • 更重要的是,我的警报视图委托方法不起作用,并且更新不会下载.即使我使用@property(非原子,强)UIWebView*webView引入webView,该方法也不会做任何事情.
  • 我认为Dropbox已正确配置MIME,因为我可以通过谷歌Chrome下载.ipa.

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

Nic*_*ood 5

您可以使用自动打开URL

[[UIApplication sharedApplication] openURL:...];
Run Code Online (Sandbox Code Playgroud)

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