Find My iPhone via Node.js

The Find My iPhone app is a great feature of iCloud. You can track your iCloud enabled devices to determine if you left your iPad at work or your iPhone on the bus; you can send messages or play sounds to help locate and recover them; and you can remotely lock or wipe them if you are concerned about the device being stolen. There are limitations to this service however: you must use the official Apple app (or iCloud web-page) and you cannot keep a history of previous locations.

I thought there must be a way to tap into the service to use the information for my own purposes. After-all, behind most internet-enabled things these days there is a simple JSON API. A quick Google search revealed a few people had the same idea and led me to find a few GitHub repositories for APIs that wrapped around the Find My iPhone web service.

Note: I have no idea if the iCloud EULA allows for this kind of thing. I’m not being malicious and I’m not hammering their web-service, so I think it’s probably okay. Additionally, Apple could again change their API at any time and break this implementation. Use at your own risk!

Susomi – PHP Script

I initially trialled Susomi, a PHP script that allowed full-access to the Find My iPhone service, including locating devices, sending messages, remote locking and wiping of lost devices. A year ago this script worked great. Unfortunately since that time, it seems that the Find My iPhone API has changed and the script has not been updated to keep up with the changes.

I did find a gist that promised to support the updated API and a few other repositories that supposedly worked, but I had little success. Additionally, I wanted to experiment with something a bit more “cutting edge” than PHP so rather than repairing the scripts myself, I started looking for Node.js equivalents.

iPhone-Finder – Node.js

Further searches of GitHub revealed a couple of Node.js libraries for interacting with the Find My iPhone API. Similar to my PHP search, a lot of these packages had been written once and never updated when the API changed. Fortunately, I discovered iphone-finder and it seemed to work out of the box.

The features supported by the lightweight iphone-finder package are much more limited than Susomi: you can only retrieve the “device info”, rather than having the option to send messages, lock the device, etc. However, for the purposes I planned on using this API, this was perfect.

Getting Your iPhone’s Location

First you need to install the iphone-finder library. A simple NPM command will sort that out:

npm install iphone-finder

You also need to provide iphone-finder with your iCloud username and password. As usual, you should take precautions to make sure any script is not trying to steal your personal information. You can browse the iphone-finder code on GitHub to reassure yourself it isn’t doing anything bad.

The following Node.js snippet will print the name, type and location of the newest device on your iCloud profile to the console.

var iPhoneFinder = require('iphone-finder');
var iCloudUser = '';
var iCloudPass = '#############';

iPhoneFinder.findAllDevices(iCloudUser, iCloudPass, function(err, devices) {
    var device = devices[0];

    console.log("Device name: " +;
    console.log("Device Type: " + device.modelDisplayName);
    console.log("Device Latitude: " + device.location.latitude);
    console.log("Device Longitude: " + device.location.longitude);

Executing the above will result in the something similar to the following output:

Device name: Chris' iPhone
Device Type: iPhone
Device Latitude: 55.948559
Device Longitude: -3.199771

The device variable contains lots of information, including: the horizontal accuracy of the location (in metres); the type of location fix (GPS / Wifi / etc); the battery level; the time-stamp of the location fix; and details regarding the device being lost, etc. Full details are available on this gist.

Building on Basic Tracking

The above code snippet provides a useful base to build on. Knowing the current location of an iCloud connected device is useful and the API enables this basic information to be used to build a larger application or utility.

What are the possibilities?

  • I have written a Node.js application to poll the location of my iPhone at regular intervals and log the location. This application provides a historical trace of where I’ve been and shows the places I frequent most. More details are coming soon.
  • I have also integrated the iCloud device location with my magic screen project to provide a high-level estimate of my current location. More details are coming soon.
  • It would be possible to integrate the phone’s location with a set of rules to perform tasks based on the location. For example, if you were travelling between work and home the phone could turn on the heating in your house.
  • A web service could send you messages with information from Wikipedia about the nearest place of interest as you walked around a city.

Avoid OpenShift Application Idling


OpenShift is a great Platform-as-a-Service provided by Red Hat to host web applications in a cloud environment. I use OpenShift to host a few services, such as my iPhone Tracking service (coming soon).

The OpenShift free plan provides three small Amazon EC2 instances to use without a CPU, memory or bandwidth cap – this is perfect for running some of the small web applications I develop. However, the free plan also has a big limitation: if an application does not receive an HTTP request within 24 hours, it will be suspended.

This limitation is fine if you are running a standard website. Once asleep, the next HTTP request will simply take a few seconds longer to respond as the EC2 instance is spun up. However, if you are running a web service that needs to perform a task at regular intervals, such as tracking the location of your mobile phone, then you do not want the application to idle.


To work around this limitation, you simply have to ensure an HTTP request is made to your service every 24 hours from outside of your EC2 instance. The best way I have found to do this is by registering the site with an “uptime checker”, such as UptimeRobot.

UptimeRobot makes an HTTP request to my web service every 5 minutes to check it is running. This is perfect for ensuring my OpenShift instance does not idle due to inactivity and also provides me with a monitoring service for my application.

Running Scheduled Tasks In Node.js

Lots of web services need to run tasks at a particular time. This could be to perform a clean-up or maintenance operation, or simply to retrieve and process some data.

JavaScript has built in methods for running a task in a scheduled number of seconds. However, the syntax and architecture of these methods is a bit clumsy and there is no built in management to cancel jobs.

Fortunately in Node.js there are many libraries that perform just these tasks. One of these libraries is node-crontab which is available on GitHub or NPM.

The syntax of node-crontab is simple and straightforward, particularly if you have ever set up a scheduled task using cron on a linux system before. The time for the scheduled task is provided in cron format (either a specific time to run at, or a time interval); the task is provided as a function to run. There are some other optional parameters, such as the possibility of passing in arguments, changing what this points to, and stopping the task from running repeatedly.

The following code will print the message “I am running from cron” to the log every 15 minutes:

var cron = require('node-crontab');
var log_job = cron.scheduleJob("*/15 * * * *", function() {
    console.log("I am running from cron");

To run a task at 0315 every morning, use the following code:

var early_morning = cron.scheduleJob("15 3 * * *", function() {
    console.log("It's very early in the morning!");

To kill an existing job:


In summary, node-crontab is very simply to use and great for scheduling tasks in Node.js