TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2017 |
Maintained by Hatena, yashigani.
Integrate Hatena Bookmark into your application. This is an Objective-C library for handling the Hatena Bookmark API and for providing a user interface.
Register your app information at Hatena Developer Center. This SDK needs all scope, read_public, read_private, write_public, write_private.
After registration, you will get a consumer key and a consumer secret.
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"];
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];
}
The SDK provides two ways for integrating the Hatena Bookmark Panel UI.
UIActivity is an iOS native sharing interface, available on iOS 6 or later.
This SDK provides HTBHatenaBookmarkActivity
.
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];
}
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.
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];
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
.
Clone this repository and run make clean test
in root directory.
/SDK/API/
/SDK/UI/
HTBHatenaBookmkarkManager
iOS SDK interfaces with the Hatena Bookmark API. For more details, see api docs (In Japanese).