Downloading Device UDIDs from Apple Developer Portal

Downloading Device UDIDs from Apple Developer Portal

September 30, 2011   ·   By Denis Hennessy

Apple allows an iOS developer to associate up to 100 devices with a developer account, and use those devices for testing Ad-Hoc builds. Although there's an option to remove devices, they continue to count towards the 100 device limit. That is, until you renew your developer account - then you get a message that you can delete devices and have them no longer apply against the limit. In past years, I've tried to carefully prune the list, but inevitably I've overlooked a bunch of devices and once you start adding new devices, you can no longer delete old ones.

This year, I have a new plan. I'm going to delete all devices, except for my own, and then gradually re-add client devices as they're needed. The developer portal has a useful option to upload a text file containing a list of devices but unfortunately doesn't have an option to download the existing devices. Using the excellent mechanize gem, I wrote a short script to scrape the UDIDs from the developer portal and export them to a local file. Here's how you use it:

$ ruby dl_devices.rb myappleid mypassword > devices.txt

Here's the source of the script:

require 'rubygems'
require 'mechanize'

agent = Mechanize.new
page = agent.get("https://developer.apple.com/ios/manage/devices/index.action")

# Log in to Apple Developer portal if we're presented with a login form
form = page.form_with :name => 'appleConnectForm'
if form
  form.theAccountName = ARGV[0]
  form.theAccountPW = ARGV[1]
  form.submit
  page = agent.get("https://developer.apple.com/ios/manage/devices/index.action")
end

puts "deviceIdentifier\tdeviceName"

# Format each row as name,udid
rows = page.parser.xpath('//fieldset[@id="fs-0"]/table/tbody/tr')
rows.each do |row|
  name = row.at_xpath('td[@class="name"]/span/text()')
  udid = row.at_xpath('td[@class="id"]/text()')
  puts "#{udid}\t#{name}"
end

Click dl_devices.rb to download it. It simply tries to access the device management page, fills in a login form if required, and then extracts the device name and UDID using xpath expressions.

Troubleshooting

If you get an error like 'gem_original_require': no such file to load -- mechanize (LoadError), it means you don't have the required ruby libraries installed. Install them with:

$ gem install mechanize

If the resulting data is missing or garbage, then it's possible that Apple have changed the structure or flow of the developer portal. Try manually visiting https://developer.apple.com/ios/manage/devices/index.action and verify that you get asked to login, and then see your list of devices. If the structure of the page has changed, you could adjust the xpath references to match. If so, please send me the changes and I'll update this page.

 

Post Comments

blog comments powered by Disqus

© Copyright 2009-2012 Peer Assembly | All Rights Reserved.