Coder Social home page Coder Social logo

hatena-bookmark-ios-sdk's Introduction

Hatena Bookmark iOS SDK

travis-ci

Integrate Hatena Bookmark into your application. This is an Objective-C library for handling the Hatena Bookmark API and for providing a user interface.

Main Screenshot

Install

CocoaPods

Add the lines below to your Podfile.

platform :ios, '5.0'

pod 'HatenaBookmarkSDK'

Without CocoaPods

Clone this repository.

git clone --recursive https://github.com/hatena/Hatena-Bookmark-iOS-SDK.git

Copy /SDK/ directory and add dependent modules AFNetworking and SFHFKeychainUtils to your project .

Usage

Register OAuth

Register your app information at Hatena Developer Center. This SDK needs all scope, read_public, read_private, write_public, write_private.

Scope Settings

After registration, you will get a consumer key and a consumer secret.

Consumer Key and Consumer Secret

Initialize

At first SDK needs initialization with consumer key and secret. You should add below initalization code at application:didFinishLaunchingWithOptions: or other initalize section.

[[HTBHatenaBookmarkManager sharedManager] setConsumerKey:@"your consumer key" consumerSecret:@"your consumer secret"];

Authorization

The SDK needs to login with OAuth before making a request to the API. Add authorization code your app's settings view.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showWebView:) name:kHTBLoginStartNotification object:nil];

[[HTBHatenaBookmarkManager sharedManager] authorizeWithSuccess:^{

} failure:^(NSError *error) {

}];

After making an authorization request, the SDK calls kHTBLoginStartNotification with NSURLRequest including the login page URL. You should handle the notification and request with HTBLoginWebViewController.

-(void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showOAuthLoginView:) name:kHTBLoginStartNotification object:nil];
}

-(void)showOAuthLoginView:(NSNotification *)notification {
    NSURLRequest *req = (NSURLRequest *)notification.object;
    UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[HTBNavigationBar class] toolbarClass:nil];
    HTBLoginWebViewController *viewController = [[HTBLoginWebViewController alloc] initWithAuthorizationRequest:req];
    navigationController.viewControllers = @[viewController];
    [self presentViewController:navigationController animated:YES completion:nil];
}

Login Screenshot

Bookmark UI

The SDK provides two ways for integrating the Hatena Bookmark Panel UI.

  • HTBHatenaBookmarkActivity
  • HTBHatenaBookmarkViewController

HTBHatenaBookmarkActivity

UIActivity is an iOS native sharing interface, available on iOS 6 or later. This SDK provides HTBHatenaBookmarkActivity.

iPhone / iPod touch

You can present a UIActivityViewController modally on iPhone or iPod touch.

NSURL *URL = self.webView.request.URL;

// iOS 6 or later
if ([UIActivityViewController class]) {
    HTBHatenaBookmarkActivity *hateaBookmarkActivity = [[HTBHatenaBookmarkActivity alloc] init];
    UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:@[URL]                                                                               applicationActivities:@[hateaBookmarkActivity]];
    [self presentViewController:activityView animated:YES completion:nil];
}

UIActivity Screenshot

iPad

Apple official document said that "on iPad, it must be presented in a popover".

NSURL *URL = self.webView.request.URL;

// iOS 6 or later
if ([UIActivityViewController class]) {
    HTBHatenaBookmarkActivity *hateaBookmarkActivity = [[HTBHatenaBookmarkActivity alloc] init];
    UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:@[URL]                                                                               applicationActivities:@[hateaBookmarkActivity]];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // on iPad
        self.activityPopover = [[UIPopoverController alloc] initWithContentViewController:activityView];
        __weak UIPopoverController *weakPopover = self.activityPopover;
        activityView.completionHandler = ^(NSString *activityType, BOOL completed){
            // dismiss popover on activity completed.
            [weakPopover dismissPopoverAnimated:YES];
        };
        [self.activityPopover presentPopoverFromBarButtonItem:sender
                                     permittedArrowDirections:UIPopoverArrowDirectionAny
                                                     animated:YES];
    }
}

See HTBDemoViewController for detail.

HTBHatenaBookmarkViewController

You can call ViewController directly.

// iOS 5
NSURL *URL = self.webView.request.URL;
HTBHatenaBookmarkViewController *viewController = [[HTBHatenaBookmarkViewController alloc] init];
viewController.URL = URL;
[self presentViewController:viewController animated:YES completion:nil];

Build DemoApp

Clone this repository and run git submodule update --init. After that, open /DemoApp/DemoApp.xcodeproj and build.

Demo app also needs OAuth consumer secret and key. Add to [[HTBHatenaBookmarkManager sharedManager] setConsumerKey:@"your consumer key" consumerSecret:@"your consumer secret"]; in HTBDemoViewController.

Running Tests

Clone this repository and run make clean test in root directory.

Archtecture

  • /SDK/API/
  • HTTP request class
  • /SDK/UI/
  • Some classes related in bookmark panel UI and login
  • HTBHatenaBookmkarkManager
  • Core module
  • Handle user login information
  • Dispatch JSON response to model class

Requirements

  • iOS 5.0 or later
  • ARC

Dependency

Hatena Bookmark API

iOS SDK interfaces with the Hatena Bookmark API. For more details, see api docs (In Japanese).

License

MIT license.

hatena-bookmark-ios-sdk's People

Contributors

ninjinkun avatar giginet avatar laiso avatar 0x0c avatar kishikawakatsumi avatar

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.