Programmatically click on HTML href to update the application.

I am planning updates for an enterprise application with ad-hoc distribution.

For updates, Apple recommends that the user visit the HTML page and touch the link:

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

See http://help.apple.com/iosdeployment-apps/#app43ad871e

I do not want to do this. I want the application to programmatically check for updates at startup and warn the user with UIAlertView that the update is available.

Here is what I still have in the didFinishLaunching application. Complex syntax analysis comes from the structure of the plist example found here: 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];
        }       
    }
}

Then I have my delegate method 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]];
    }
}

Few things:

  • , [alert show] didFinish, .
  • , plistData .
  • , , . webView @property (, ) UIWebView * webView, .
  • , Dropbox MIME , .ipa Google Chrome.

, NSURLConnection (NSURLRequest ..) , HTML href. , .

+5
1

URL- ,

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

, itms-services: urls, URL, tel:, fb: .., , Apple .

+5

All Articles