Create Index Page for App Store AdHoc Apps

Usually we use AdHoc distributions to share our apps to testers or important clients.

When we create those apps, we will get a plist file and an ipa file and upload these two files to our web server.

It’s better to have an automatically generated index page rather than manually modifying an HTML page.

This is an example to create such a dynamic page using PHP 5.

At the beginning, we need to support iPhone / iPad devices by adding the following viewport option:

<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>

First, we will scan the current folder and gather all the plist file infos:

$plists = array();

// read all plist files in the current folder
if ($handle = opendir(‘.’))
{

// enum current folder
while (($entry = readdir($handle)) !== false)
{
// check extension to accept .plist only
$ext = pathinfo($entry, PATHINFO_EXTENSION);
if ($ext != “plist”) continue;

$plists[] = array(‘file’ => $entry, ‘time’ => filemtime($entry));
}

closedir($handle);
}

Secondly, we’d better sort the list by the last modified time, of course, descending:

// sort plists by last modified time
function cmp($a, $b)
{
if ($a[‘time’] == $b[‘time’]) return 0;
return $a[‘time’] > $b[‘time’] ? -1 : 1;
}
uasort($plists, ‘cmp’);

We should create links directly to the plist files. Here’s the prefix of those links:

// generate link prefix
$prefix = ‘itms-services://?action=download-manifest&url=http://’.$_SERVER[‘HTTP_HOST’].dirname($_SERVER[‘PHP_SELF’]).’/’;

At last, we enum each plist file info and output them as a <li> tag:

// show all plists
foreach ($plists as $info)
{
$url = $prefix.$info[‘file’];

// extract plist info
$plist = simplexml_load_file($info[‘file’]);

// // fetch url link
// $url = $plist->dict->array->dict->array->dict->string[1];

// fetch metadata
$node = $plist->dict->array->dict->dict;
$meta = array();
for ($i=0; $i < count($node->key); $i++)
{
$meta[$node->key[$i].”] = $node->string[$i];
}

// fetch version and title
$version = $meta[‘bundle-version’];
$title = $meta[‘title’];
$subtitle = isset($meta[‘subtitle’]) ? $meta[‘subtitle’] : ”;

?>
<li>
<a href=”<?php echo $url?>”><?php echo $title?></a>
<span class=”note”> (<?php echo $version?>) </span>
<div><?php echo $subtitle?></div>
</li>
<?php
}

?>

That’s it!

In this approach, we can even use SubTitle field to add extra Html information into our index page list.

Published by

vivo

This is Vivo. Yes, I'm Vivo.

Leave a Reply

Your email address will not be published. Required fields are marked *