Git Product home page Git Product logo

pocket-objc-sdk's Introduction

This SDK is deprecated

Howdy all! 👋 Thanks for checking out this repo. Your 👀 mean a lot to us. 💗

Unfortunately, this project is deprecated, and the code hosted here is woefully out of date. We wouldn't recommend it as anything other than a curiosity.

If you're interested in developing against the Pocket API, please visit our Developer Documentation.

Welcome!

Thanks for checking out the Pocket SDK. With a few lines of code, your app can quickly add support for saving URLs to users' Pocket lists.

Installing the Pocket SDK

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.

Step 1: Download the Pocket SDK

You can download the SDK at: http://getpocket.com/api/v3/pocket-objc-sdk.zip

You can also watch/checkout the SDK from GitHub at: http://github.com/Pocket/Pocket-ObjC-SDK. If you use recommend adding the Pocket SDK as a git submodule of your project by running git submodule add git://github.com/Pocket/Pocket-ObjC-SDK.git <path> from the root directory of your repository, replacing the <path> with the path you'd like it installed to.

If you use CocoaPods, you can add the PocketAPI pod to your Podfile. Then run pod install, 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.

The project download includes the SDK and an example project.

Step 2: Add the Pocket SDK to your project

  • Open your existing project.
  • Drag the SDK folder from the example project into your Xcode project.
  • Make sure the “Copy items into destination group’s folder (if needed)” checkbox is checked.
  • 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.

The SDK includes all necessary source files and does not have any other dependencies.

###Step 3: Obtain a platform consumer key###

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.

If you have not obtained a consumer key yet, you can register one at http://getpocket.com/api/signup

Step 4: Add the Pocket URL scheme

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 "pocketapp" plus your application'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 "pocketapp42".

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 [[PocketAPI sharedAPI] setURLScheme:@"YOUR-URL-SCHEME-HERE"]. To add a URL Scheme, create a block like the one below in your Info.plist, updating it with the app’s scheme:

▾ 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"]

Or you can copy and paste the following into the XML Source for the Info.plist:

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLName</key>
		<string>com.readitlater</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>pocketapp9553</string>
		</array>
	</dict>
</array>

Step 5: Configure your App Delegate

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.

Import the PocketAPI Header

At the top of your app delegate source file (and anywhere you call the PocketAPI object), you'll need to include the PocketAPI header. At the top of your class you'll probably see other imports already. Simply add this line:

#import "PocketAPI.h"

Set Your Platform Consumer Key

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:

[[PocketAPI sharedAPI] setConsumerKey:@"Your Consumer Key Here"];

Add a method for the Pocket url-scheme

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:

-(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;
    }

}

Step 6: Start Saving to Pocket!

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:

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
    }
}];

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 delegate or operation based methods.

Managing Accounts / Handling User Logins

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:

[[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
}
}];

It is also recommended to observe changes to the PocketAPI'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.

Calling Other Pocket APIs

To call other arbitrary APIs, pass the API'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.

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
 }];

Enabling Extension Support

The first step is to "Enable Keychain Sharing" in both your app and extension capabilities in Xcode.

See Configuring Keychain Sharing for more information.

Final step is to add the following before you initialize the PocketAPI in your main app and extension:

[[PocketAPI sharedAPI] enableKeychainSharingWithKeychainAccessGroup:@"Your Keychain Access Group"];
[[PocketAPI sharedAPI] setConsumerKey:@"Your Consumer Key Here"];

After enabling keychain sharing, the app and extensions can access data that is securely stored in the keychain. From now on you can use the default methods of the PocketAPI class to save links from within extensions. See Step 6: Start Saving to Pocket! for more details.

Acknowledgements

The Pocket SDK uses the following open source software:

License

Copyright (c) 2015 Read It Later, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", 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.

pocket-objc-sdk's People

Contributors

djds23 avatar ideashower avatar jyopp avatar larrrrryt avatar maicki avatar nchapman avatar nzeltzer avatar readmecritic avatar stevestreza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pocket-objc-sdk's Issues

Getting saved values in PocketAPIKeychainUtils

@maicki: In the feature/extension-support branch, it appears that the following change (to include accessGroup) is warranted in #storeUsername:andPassword:forServiceName:inAccessGroup:updateExisting:error:

--- a/SDK/PocketAPIKeychainUtils.m
+++ b/SDK/PocketAPIKeychainUtils.m
@@ -162,7 +162,7 @@ static NSString *PocketAPIKeychainUtilsErrorDomain = @"PocketAPIKeychainUtilsErr

 	// See if we already have a password entered for these credentials.
 	NSError *getError = nil;
-	NSString *existingPassword = [PocketAPIKeychainUtils getPasswordForUsername: username andServiceName: serviceName error:&getError];
+	NSString *existingPassword = [PocketAPIKeychainUtils getPasswordForUsername: username andServiceName: serviceName inAccessGroup:accessGroup error:&getError];

 	if ([getError code] == -1999) {
 		// There is an existing entry without a password properly stored (possibly as a result of the previous incorrect version of this code.

Remove SFHFKeychainUtils

Hi Steve,

Could you please make SFHFKeychainUtils a dependency in cocoapods file and remove it from the SDK folder? As of right now, it results in Xcode warning "Multiple build commands for output file" when some other pods have SFHFKeychainUtils as their dependency.

Operation queue is blocked after relogging

Hi,
I've noticed that the handler block in PocketAPI -callAPIMethod:withHTTPMethod:arguments:handler: is not called after the user is successfully relogged. After further investigation I've found that operationQueue is blocked after relogging.

Steps to reproduce:

  1. Log in with PocketAPI -loginWithHandler:.

  2. Go to Connected Applications at getpocket.com and revoke access to the application.

  3. Call -callAPIMethod:withHTTPMethod:arguments:handler:. handler block is called with the error 401, as expected.

  4. Redirect to Safari/Pocket is triggered. Click on "Authorize".

  5. Request from 3. should be re-run, but it's left in the operationQueue indefinitely. po [[PocketAPI sharedAPI].operationQueue operations] returns:

    <__NSArrayM 0xb627080>(
    <PocketAPIOperation: 0xb656b30 https://getpocket.com/v3get {
    count = 20;
    detailType = complete;
    since = 1384691485;
    sort = newest;
    state = all;
    }>,
    <PocketAPIOperation: 0xb5ab910 https://getpocket.com/v3get {
    count = 20;
    detailType = complete;
    since = 1384691485;
    sort = newest;
    state = all;
    }>
    )
    
  6. Further requests are also not processed because the operationQueue is blocked.

loginWithHandler never calls callback

'm trying to login with pocket:

[[PocketAPI sharedAPI] loginWithHandler: ^(PocketAPI *API, NSError *error){
    NSLog(@"FINISHED")
}];

After this call, I'm being redirected to Pocket app, after I click "Authorize" button, I'm being redirected back to my app. But NSLog(@"FINISHED"); had never been called.

Also in my AppDelegate.m I have this method:

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  if([[PocketAPI sharedAPI] handleOpenURL:url]){
    NSLog(@"YES, %@", url);
    return YES;
  }else{
    // if you handle your own URLs, do it here
    return NO;
  }
}

It gets called after I click on "Authorize" button, and I see YES, pocketapp*****:authorizationFinished in the console.

Why loginWithHandler callback never gets called?

ARC

any plans in releasing an ARC version?

[Minor] Documentation smart quotes

At several points in the documentation, smart quotes are used within code blocks, rendering it invalid. Specifically, step 5 (first sub-step) and step 6.

iOS App using Pocket-ObjC-SDK is rejected because of OAuth login with Safari.

My application which use Pocket API is rejected because of logging in with Safari.
**
Reasons

10.6: Apple and our customers place a high value on simple, refined, creative, well thought through interfaces. They take more work but are worth it. Apple sets a high bar. If your user interface is complex or less than very good it may be rejected
10.6

We found the following issues with the user interface of your app: The app opens a web page in mobile Safari for logging in, then returns the user to the app. The user should be able log in without opening Safari first.
**

I explained like this.
**
This application's target user has already had "Pocket" app which is free app. If they have "Pocket", they can login without Safari. Is this enough for this?
**

But they answered like this.
**
Thank you for your response regarding your app. However, we will still require login within the app.
**
What a silly reason this is.

I made pull request today. If you have a same problem, fork my solution.

access to acces_token

is there any way that we can use the iOS SDK for authentification and then get the access token whihc would allow us to fetch articles server side? would this be frowned upon as a way of doing things?

I know it works the other way around, the node.js lib for instance gives us the login url that we can use on the client side and then we can do the rest on the server side.

cheers

Broken when bridging over to use with Swift

I've tried it on both on iOS and OSX, and the error is occurring at the same place. When instantiating UIApplication on iOS or NSWorkspace on iOS, it throws the following error:

Semantic Issue: Use of undeclared identifier 'UIApplication' (for iOS, on OSX it's 'NSWorkspace' in the error).

I have an open stackoverflow question trying to get to the root of it as well, but any help from your side would be very much appreciated.

The bridging is working fine, but I had to add the '-fno-objc-arc' to all the pocket api files, so it doesn't freak out over ARC.

Update: got it working on iOS by adding the following in PocketAPI.m and PocketAPILogin.m right below the imports.

#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
#import <UIKit/UIKit.h>
#endif

Update 2:

Got it working on OSX and iOS by adding the following after the imports in PocketAPILogin.m and PocketAPI.m:

#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
#import <UIKit/UIKit.h>
#endif

#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
#import <Appkit/AppKit.h>
#endif

Can do a fork/pull request for it if you want.

User Cocoapods dependency for SFHFKeychainUtily?

Instead of using SFHFKeychainUtily directly in the project have Cocoapods dependency. Adding files directly can cause conflicts with other pods using SFHFKeychainUtily and can cause duplicate-symbol compile error.

"loginWithHandler" cannot call back in iOS7

I'm using this SDK on Xcode 5.1 for developing an APP(using ARC).

And I use this method to authorize. When the program call this method it can redirect to the authorize web page and after click the "Authorize" button it can go back to the app. However, nothing happens after that. I am not login and and code in the block never be call.

I also want to catch "PocketAPILoginFinishedNotification" by using NSNotificationCenter but don't success.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.