When I install the Square app on a brand-new iPhone, it prepopulates my first name, last name, and e-mail into the signup fields. All I have to type is a password. That's really neat.
How does that work, and how does it know who I am? Is this using a privileged API? There's no programmatic way to get a user's name, AFAIK.
I was actually curious about this too, so I checked it out myself earlier. It's a very clever trick. Here's how it works:
First, Square accesses the name of your iPhone. (This isn't a protected API.)
For most people, the default name of the phone is something along the lines of "Steve Smith's iPhone". A regular expression match is performed, parsing out "Steve Smith".
"Steve Smith" is then searched for in your contact list.
If an entry is found, it brings back the first/last names and the e-mail address for that contact. The signup form is prepopulated accordingly.
If an entry is not found, the signup form will stay blank. Likewise, if the name of your iPhone is something other than the default format -- even if it's just one character off -- the prepopulation mechanism won't fire.
You can prove that this works by changing the name of your iPhone to an arbitrary contact, as in "Dave Wilson's iPhone", and noticing that Dave Wilson's contact info will now be prepopulated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With