【问题标题】:Programmatically tap on HTML href in order to update app以编程方式点击 HTML href 以更新应用程序
【发布时间】: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 的行为的方法。在那之后,我认为会发生完整的更新。

【问题讨论】:

    标签: iphone ios ipad adhoc


    【解决方案1】:

    您可以使用自动打开网址

    [[UIApplication sharedApplication] openURL:...];
    

    我不知道它是否适用于 itms-services: urls,但它适用于其他定制的 URL 方案,如 tel:、fb: 等,因此除非 Apple 明确阻止它,否则它应该这样做。

    【讨论】:

    • Apple 似乎已经开始以这种方式阻止使用 itms-services。幸运的是,仍然可以要求用户点击涉及 itms-services 的 href 链接。
    • 我也没有成功从应用程序中打开 itms-services 网址。我想这只是意味着用户需要额外点击几下才能找到并按下网页上的下载按钮。不知道为什么他们会阻止它,如果它可以从网页上完成的话。
    • 这似乎在模拟器中不起作用,但在真实设备上很好。让我困惑了一段时间。
    • @JustinCaldicott 那是因为模拟器上没有 App Store.app。
    • @JustinCaldicott 实际上很抱歉,这不是那个原因(itms-apps:// 没有通过应用商店)。这可能只是因为您无法在模拟器上安装临时构建(它们是为 ARM 而不是 x86 构建的,并且配置类型错误)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多