{"title":"Delight Your Users By Pre-filling Forms With JBDeviceOwner","html_url":"https://deallocatedobjects.com/posts/delight-your-users-by-pre-filling-forms-with-jbdeviceowner","source_url":"https://github.com/jakeboxer/JBDeviceOwner","markdown_content":"Filling out forms on a phone can really suck. Heck, even on the iPad's awesome screen, I often make plenty of mistakes while typing in information. \r\n\r\nWhen a user first downloads your iOS app, it's quite common for them to need to fill out some sort of \"sign up\" or some other kind of form.\r\n\r\nAll of this can add up to a terrible \"first run\" experience for new users of your app.\r\n\r\nWhat's a developer to do? \r\n\r\nEnter: `JBDeviceOwner`\r\n\r\nThis simple library, which comes to us from [Jake Boxer](http://jakeboxer.com/), uses the *name* of the user's device to look up and return commonly needed user information from their Address Book record.\r\n\r\nHere's what it looks like in action:\r\n\r\n``` objc\r\nJBDeviceOwner *owner = [UIDevice currentDevice].owner;\r\n\r\n// owner will be nil if the user's data could not be found.\r\nif (owner != nil) {\r\n  self.firstNameTextField.text = owner.firstName;\r\n  self.lastNameTextField.text  = owner.lastName;\r\n  self.emailTextField.text     = owner.email;\r\n  self.phoneTextField.text     = owner.phone;\r\n}\r\n```\r\n\r\nJake describes how it works:\r\n\r\n> It's really simple actually.\r\n\r\n> Most iPhones are named *\"Jake Boxer's iPhone\"* (\"sometimes with a different person's name instead of mine). Most iPhones have their owner saved in their address book.\r\n\r\n> `JBDeviceOwner` extracts the owner's name from the device name, finds the matching record in the address book, and populates the `JBDeviceOwner` instance with the data from the record.\r\n\r\n> If `JBDeviceOwner` can't figure out the owner's name, or if it can't find a matching record in the address book, it won't return anything.\r\n\r\nObviously this approach, while really neat, isn't going to work for absolutely every user, so you should have a sensible \"fall back\". I like to \"try grabbing\" using `JBDeviceOwner`, and if I don't find anything, try manually asking the user to enter their email, then using *that email address* to try to locate their contact record.\r\n\r\nTry not to over-do it, but I believe when done well, this sort of approach can be an awesome alternative to requiring users to type in a ton of information.\r\n\r\n*Please Note:* Try not to ask your users for a ton of information in the first place, only require what you absolutely need to make your app work.\r\n\r\nThat being said, A few big name apps are now using this technique, and their \"first run\" experiences are *much* nicer, simply prompting the user with a `UIActionSheet` with, for example: \"Would you like to use this information?\"\r\n\r\n[Check out `JBDeviceOwner` on Github](https://github.com/jakeboxer/JBDeviceOwner) and stop annoying your users today!","html_content":"<p>Filling out forms on a phone can really suck. Heck, even on the iPad’s awesome screen, I often make plenty of mistakes while typing in information. </p>\n\n<p>When a user first downloads your iOS app, it’s quite common for them to need to fill out some sort of “sign up” or some other kind of form.</p>\n\n<p>All of this can add up to a terrible “first run” experience for new users of your app.</p>\n\n<p>What’s a developer to do? </p>\n\n<p>Enter: <code>JBDeviceOwner</code></p>\n\n<p>This simple library, which comes to us from <a href=\"https://web.archive.org/web/20120508223646/http://jakeboxer.com/\">Jake Boxer</a>, uses the <em>name</em> of the user’s device to look up and return commonly needed user information from their Address Book record.</p>\n\n<p>Here’s what it looks like in action:</p>\n<figure class=\"code\" data-lang=\"objective-c\"><figcaption><span class=\"lang\">Objective-C</span></figcaption><pre class=\"shiki shiki-themes github-light github-dark\" style=\"--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">JBDeviceOwner </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">*</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">owner </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> [UIDevice </span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">currentDevice</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">].owner;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span style=\"--shiki-light:#6A737D;--shiki-dark:#6A737D\">// owner will be nil if the user's data could not be found.</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">if</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> (owner </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">!=</span><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\"> nil</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">) {</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.firstNameTextField.text </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> owner.firstName;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.lastNameTextField.text  </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> owner.lastName;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.emailTextField.text     </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> owner.email;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#005CC5;--shiki-dark:#79B8FF\">  self</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">.phoneTextField.text     </span><span style=\"--shiki-light:#D73A49;--shiki-dark:#F97583\">=</span><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\"> owner.phone;</span></span>\n<span class=\"line\"><span style=\"--shiki-light:#24292E;--shiki-dark:#E1E4E8\">}</span></span></code></pre></figure>\n<p>Jake describes how it works:</p>\n\n<blockquote>\n<p>It’s really simple actually.</p>\n\n<p>Most iPhones are named <em>“Jake Boxer’s iPhone”</em> (“sometimes with a different person’s name instead of mine). Most iPhones have their owner saved in their address book.</p>\n\n<p><code>JBDeviceOwner</code> extracts the owner’s name from the device name, finds the matching record in the address book, and populates the <code>JBDeviceOwner</code> instance with the data from the record.</p>\n\n<p>If <code>JBDeviceOwner</code> can’t figure out the owner’s name, or if it can’t find a matching record in the address book, it won’t return anything.</p>\n</blockquote>\n\n<p>Obviously this approach, while really neat, isn’t going to work for absolutely every user, so you should have a sensible “fall back”. I like to “try grabbing” using <code>JBDeviceOwner</code>, and if I don’t find anything, try manually asking the user to enter their email, then using <em>that email address</em> to try to locate their contact record.</p>\n\n<p>Try not to over-do it, but I believe when done well, this sort of approach can be an awesome alternative to requiring users to type in a ton of information.</p>\n\n<p><em>Please Note:</em> Try not to ask your users for a ton of information in the first place, only require what you absolutely need to make your app work.</p>\n\n<p>That being said, A few big name apps are now using this technique, and their “first run” experiences are <em>much</em> nicer, simply prompting the user with a <code>UIActionSheet</code> with, for example: “Would you like to use this information?”</p>\n\n<p><a href=\"https://github.com/jakeboxer/JBDeviceOwner\">Check out <code>JBDeviceOwner</code> on Github</a> and stop annoying your users today!</p>","created_at":"2013-11-16T05:10:25.564Z","updated_at":"2013-11-16T05:10:25.564Z"}