Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

187 lines (130 sloc) 10.902 kb
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta name="Format" content="complete" />
</head>
<body>
<h1 id="welcome">Welcome!</h1>
<p>Thanks for checking out the Pocket SDK. With a few lines of code, your app can quickly add support for saving URLs to users&#8217; Pocket lists.</p>
<h2 id="installingthepocketsdk">Installing the Pocket SDK</h2>
<p>The Pocket SDK is the fastest way to add Pocket integration to any iOS or Mac application. Adding the Pocket SDK to your app is incredibly easy. Follow the steps below and you can be saving urls to Pocket from your app within 15 minutes.</p>
<h3 id="step1:downloadthepocketsdk">Step 1: Download the Pocket SDK</h3>
<p>You can download the SDK at: <a href="http://getpocket.com/api/v3/pocket-objc-sdk.zip">http://getpocket.com/api/v3/pocket-objc-sdk.zip</a></p>
<p>You can also watch/checkout the SDK from GitHub at: <a href="http://github.com/pocketco/Pocket-ObjC-SDK">http://github.com/pocketco/Pocket-ObjC-SDK</a>. If you use recommend adding the Pocket SDK as a git submodule of your project by running <code>git submodule add git://github.com/Pocket/Pocket-ObjC-SDK.git &lt;path&gt;</code> from the root directory of your repository, replacing the <code>&lt;path&gt;</code> with the path you'd like it installed to.</p>
<p>If you use <a href="http://cocoapods.org/">CocoaPods</a>, you can add the <code>PocketAPI</code> pod to your Podfile. Then run <code>pod install</code>, and the Pocket SDK will be available in your project. See the documentation on the CocoaPods website if you want to set up a new or existing project.</p>
<p>The project download includes the SDK and an example project.</p>
<h3 id="step2:addthepocketsdktoyourproject">Step 2: Add the Pocket SDK to your project</h3>
<ul>
<li>Open your existing project. </li>
<li>Drag the SDK folder from the example project into your Xcode project.</li>
<li>Make sure the “Copy items into destination group’s folder (if needed)” checkbox is checked.</li>
<li>Select your Xcode project in the Project Navigator, select your application target, select “Build Phases”, and add Security.framework to your “Link Binary With Libraries” phase.</li>
</ul>
<p>The SDK includes all necessary source files and does not have any other dependencies.</p>
<p><img id="" src="https://s3.amazonaws.com/pocket-assets/adding-sdk.png" alt="" title="Dragging the SDK to your XCode project" /></p>
<p><img id="" src="https://s3.amazonaws.com/pocket-assets/adding-security-framework.png" alt="" title="Security.framework is in the Link Binary With Libraries Build Phase" /></p>
<h3 id="step3:obtainaplatformconsumerkey">Step 3: Obtain a platform consumer key</h3>
<p>When you register your app with Pocket, it will provide you with a platform consumer key. This key identifies your app to Pocket’s API.</p>
<p>If you have not obtained a consumer key yet, you can register one at <a href="http://getpocket.com/api/signup">http://getpocket.com/api/signup</a></p>
<h3 id="step4:addthepocketurl-scheme">Step 4: Add the Pocket URL scheme</h3>
<p>Once you have the consumer key for the platform you are supporting, the application must register a URL scheme to receive login callbacks. By default, this is &#8220;pocketapp&#8221; plus your application&#8217;s ID (which you can find at the beginning of the consumer key before the hyphen). So if your consumer key is 42-abcdef, your app ID is 42, and your URL scheme will be &#8220;pocketapp42&#8221;. </p>
<p>If there are already URL schemes in your app’s Info.plist, you can either add the new URL scheme, or use an existing scheme by calling <code>[[PocketAPI sharedAPI] setURLScheme:@"YOUR-URL-SCHEME-HERE"]</code>. To add a URL Scheme, create a block like the one below in your Info.plist, updating it with the app’s scheme:</p>
<pre><code>▾ URL Types (Array)
▾ Item 0 (Dictionary)
URL Identifier (String) com.getpocket.sdk
▾ URL Schemes (Array) (1 item)
Item 0 (String) [YOUR URL SCHEME, like "pocketapp42"]
</code></pre>
<p>Or you can copy and paste the following into the XML Source for the Info.plist:</p>
<pre><code>&lt;key&gt;CFBundleURLTypes&lt;/key&gt;
&lt;array&gt;
&lt;dict&gt;
&lt;key&gt;CFBundleURLName&lt;/key&gt;
&lt;string&gt;com.readitlater&lt;/string&gt;
&lt;key&gt;CFBundleURLSchemes&lt;/key&gt;
&lt;array&gt;
&lt;string&gt;pocketapp9553&lt;/string&gt;
&lt;/array&gt;
&lt;/dict&gt;
&lt;/array&gt;
</code></pre>
<h3 id="step5:configureyourappdelegate">Step 5: Configure your App Delegate</h3>
<p>The final steps to set up the Pocket SDK requires adding a few lines of code to your main app delegate. This is the class where you include iOS required methods like applicationDidFinishLaunching.</p>
<h4 id="importthepocketapiheader">Import the PocketAPI Header</h4>
<p>At the top of your app delegate source file (and anywhere you call the PocketAPI object), you&#8217;ll need to include the PocketAPI header. At the top of your class you&#8217;ll probably see other imports already. Simply add this line:</p>
<pre><code>#import "PocketAPI.h"
</code></pre>
<h4 id="setyourplatformconsumerkey">Set Your Platform Consumer Key</h4>
<p>The Pocket SDK requires your consumer key in order to make any requests to the API. Call this method with your registered consumer key when launching your app:</p>
<pre><code>[[PocketAPI sharedAPI] setConsumerKey:@"Your Consumer Key Here"];
</code></pre>
<h4 id="addamethodforthepocketurl-scheme">Add a method for the Pocket url-scheme</h4>
<p>The final step is to give the SDK an opportunity to handle incoming URLs. If you do not already implement this method on your app delegate, simply add the following method:</p>
<pre><code>-(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation{
if([[PocketAPI sharedAPI] handleOpenURL:url]){
return YES;
}else{
// if you handle your own custom url-schemes, do it here
return NO;
}
}
</code></pre>
<h3 id="step6:startsavingtopocket">Step 6: Start Saving to Pocket!</h3>
<p>At this point you’ve properly installed the SDK and can now start making requests and saving urls to Pocket. Here is a two line example:</p>
<pre><code>NSURL *url = [NSURL URLWithString:@”http://google.com”];
[[PocketAPI sharedAPI] saveURL:url handler: ^(PocketAPI *API, NSURL *URL, NSError *error){
if(error){
// there was an issue connecting to Pocket
// present some UI to notify if necessary
}else{
// the URL was saved successfully
}
}];
</code></pre>
<p>The example above uses blocks which requires iOS 4.0 or greater. If you have a need to support iOS 3.0, you can use the [linkto:delegate or operation based methods].</p>
<h2 id="managingaccountshandlinguserlogins">Managing Accounts / Handling User Logins</h2>
<p>Following Pocket’s API best practices, you’ll want to provide a way for the user to manage what account they are logged into. This is most commonly handled by adding a setting in your app’s option screen that lets the user configure their Pocket account. When the user taps this, you can simply call one line of code which will handle the entire authorization process:</p>
<pre><code>[[PocketAPI sharedAPI] loginWithHandler: ^(PocketAPI *API, NSError *error){
if (error != nil)
{
// There was an error when authorizing the user. The most common error is that the user denied access to your application.
// The error object will contain a human readable error message that you should display to the user
// Ex: Show an UIAlertView with the message from error.localizedDescription
}
else
{
// The user logged in successfully, your app can now make requests.
// [API username] will return the logged-in user’s username and API.loggedIn will == YES
}
}];
</code></pre>
<p>It is also recommended to observe changes to the PocketAPI&#8217;s username and loggedIn properties to determine when the logged-in user changes. If iOS terminates your application while it is in the background (e.g. due to memory constraints), any pending login attempts are automatically saved and restored at launch if needed. Therefore, your delegate/block responses may not get called. If you need to update UI when the logged in user changes, register for observers on PocketAPI at application launch.</p>
<h3 id="callingotherpocketapis">Calling Other Pocket APIs</h3>
<p>To call other arbitrary APIs, pass the API&#8217;s method name, the HTTP method name, and an NSDictionary of arguments. An NSDictionary with the response from the API will be passed to the handler.</p>
<pre><code>NSString *apiMethod = ...;
PocketAPIHTTPmethod httpMethod = ...; // usually PocketAPIHTTPMethodPOST
NSDictionary *arguments = ...;
[[PocketAPI sharedAPI] callAPIMethod:apiMethod
withHTTPMethod:httpMethod
arguments:arguments
handler: ^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error){
// handle the response here
}];
</code></pre>
<h1 id="acknowledgements">Acknowledgements</h1>
<p>The Pocket SDK uses the following open source software:</p>
<ul>
<li><a href="https://github.com/ldandersen/scifihifi-iphone/tree/master/security">SFHFKeychainUtils</a> for saving user credentials securely to the keychain.</li>
<li><a href="https://github.com/erica/uidevice-extension">UIDevice-Hardware</a> for creating a user agent</li>
</ul>
<h1 id="license">License</h1>
<p>Copyright (c) 2012 Read It Later, Inc.</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &#8220;Software&#8221;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED &#8220;AS IS&#8221;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.