Tools::dieError($result['userString']);
}
echo '<p>Connected!</p>' . PHP_EOL;
$result = AppleServices::viewDeveloper();
if ($result['resultCode'] != 0) {
    Tools::dieError($result['userString']);
}
echo '<p>Developer info retrieved.</p>' . PHP_EOL;
$result = AppleServices::listTeams();
if ($result['resultCode'] != 0) {
    Tools::dieError($result['userString']);
}
echo '<p>Developer teams listed.</p>' . PHP_EOL;
// TODO: For now we only take care about the one team case
$team_id = $result['teams'][0]['teamId'];
$result = AppleServices::listDevices($team_id);
if ($result['resultCode'] != 0) {
    Tools::dieError($result['userString']);
}
echo '<p>Devices listed.</p>' . PHP_EOL;
$device_found = false;
foreach ($result['devices'] as $device) {
    if ($_GET['udid'] == $device['deviceNumber']) {
        $device_found = true;
        break;
    }
}
if ($device_found) {
    echo '<p>The device is already registered.</p>' . PHP_EOL;
    echo '<p>UDID: ' . $device['deviceNumber'] . '</p>' . PHP_EOL;
    echo '<p>deviceId: ' . $device['deviceId'] . '</p>' . PHP_EOL;