ラベル 情報/開発/ライブラリ の投稿を表示しています。 すべての投稿を表示
ラベル 情報/開発/ライブラリ の投稿を表示しています。 すべての投稿を表示

[Info] AFNetworking

2011年11月18日金曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

ポスト ASIHTTPRequest と注目されているネットワークライブラリ。


並列実行に NSOperation を使い Blocks を使った APIを提供している。

用意されているクラス、プロトコル、カテゴリの一覧
AFHTTPClient
AFHTTPRequestOperation
AFImageCache
AFImageRequestOperation
AFJSONRequestOperation
AFNetworkActivityIndicatorManager
AFPropertyListRequestOperation
AFURLConnectionOperation
AFXMLRequestOperation
Protocol References
AFMultipartFormData
UIImageView(AFNetworking)
基本となるHTTPアクセスの他、画像のキャッシュや JSON/XML/PropertyList処理なども用意されている。

以下、READMEから抜粋。
// JSON Request
NSURLRequest *request = [NSURLRequest requestWithURL:
    [NSURL URLWithString:@"https://gowalla.com/users/mattt.json"]];
AFJSONRequestOperation *operation =
    [AFJSONRequestOperation JSONRequestOperationWithRequest:request
        success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
            NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"],
                   [JSON valueForKeyPath:@"last_name"]);
        } failure:nil];

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
データの種類ごと(上記例は JSON)に用意された AFHTTPRequestOperation を作成し、ここに Blocksで成功時の処理を書いておく。それを最後に NSOperationQueue へ投入するだけ。いくつかステップを踏む必要はあるが元々の NSOperation系APIを素直に活用しているので汎用性がある(あ、 JSONライブラリを別途用意する必要も無いのか)。

// Image Request
UIImageView *imageView = [[UIImageView alloc]
   initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"]
    placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
URLから画像を取得して直接 UIImageViewを作成するメソッドもある。これは簡単でいいかも。

// File Upload with Progress Callback
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
NSMutableURLRequest *request = [[AFHTTPClient sharedClient]
   multipartFormRequestWithMethod:@"POST" path:@"/upload"
   parameters:nil constructingBodyWithBlock: ^(id formData) {
  [formData appendPartWithFileData:data mimeType:@"image/jpeg" name:@"avatar"];
}];

AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc]
   initWithRequest:request] autorelease];
[operation setUploadProgressBlock:
  ^(NSUInteger totalBytesWritten, NSUInteger totalBytesExpectedToWrite) {
    NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
POST/マルチパートによるファイルアップロード処理。簡潔でわかりやすい。setUploadProgressBlock: で進捗状況をハンドリング可能。

- - - -
比較的抽象度が高く複雑な記述なしに簡単に利用できそう。ASIHTTPRequest が機能を重ねていってAPIが肥大化気味で複雑になってしまったのに対し、よく使われる機能だけに的を絞ったある意味潔いシンプルなAPI思想が個人的には気に入った。実際に使って試してみたい。


参考情報


AFNetworking Reference
AFNetworking のリファンレンスマニュアル(appledoc)

iPhone アプリ開発コミュニティのネットワークライブラリが ASIHTTPRequest から AFNetworking への移行の流れ? - laiso - iPhoneアプリ開発グループ
...と、いうことらしい。ASIHTTPRequest のメンテが終了とは知らなかった。うーむ。

人気があるのは確かなようで GitHub の Weekly/Monthly Most Wached Project としても最近上位に来ている。
watch と fork は 1,283 123 と ASIHTTPRequest にはまだ及ばないものの相当数ある。

Gowalla Engineering / AFNetworking: A Delightful Networking Library for iOS and Mac OS X

AFNetworkingの解説記事。


[Info] ネットワーク接続状況検出ライブラリ

2011年11月17日木曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

Abizern/NPReachability - GitHub


Blocks、KVOに対応。また ARCにも対応している。

typedef void (^ReachabilityHandler)(NPReachability *curReach);
- (id)addHandler:(ReachabilityHandler)handler;

@property (nonatomic, readonly, getter=isCurrentlyReachable) BOOL currentlyReachable;
@property (nonatomic, readonly) SCNetworkReachabilityFlags currentReachabilityFlags;

接続状況が変化した時に handerで定義した Blocksが実行される。引数に NPReachability を取り、接続・非接続の判断は currentlyReachableプロパティ、接続の種類(状況)は currentReachabilityFlagsプロパティで取得できる。

非常にシンプルで最低限の APIだけが提供されていてなかなかいい。


参考情報


Cocoaの日々: [iOS] ネットワーク接続状況取得ライブラリを公開
こちらも参考にどうぞ。



[Info] iPhone版Safariのようなページ切替ビュー

| Published in | 0 コメント

このエントリーをはてなブックマークに追加


iPhone版Safariのようなページ切替ビュー。こんなやつ。
ページを挿入・削除するとアニメーションが起こる。

タップするとアニメーションして画面にフィットする。画面上部にヘッダビューを付けてカスタマイズすることができる。

使い方は、まずHGPageScrollView を作りメインのビューへ貼る。
HGPageScrollView *pageScrollView =
   [[[NSBundle mainBundle] loadNibNamed:@"HGPageScrollView" owner:self options:nil] objectAtIndex:0];

[self.view addSubview:pageScrollView];
サンプルではページの定義を XIBファイルで行っていた。XIBで定義すれば容易にカスタマイズできる。

後は Data Source/Delegate を実装すればいい。
@protocol HGPageScrollViewDataSource 
@required
// Page display. Implementers should *always* try to reuse pageViews by setting each page's reuseIdentifier. 
// This mechanism works the same as in UITableViewCells.  
- (HGPageView *)pageScrollView:(HGPageScrollView *)scrollView viewForPageAtIndex:(NSInteger)index;

@optional

- (NSInteger)numberOfPagesInScrollView:(HGPageScrollView *)scrollView;   // Default is 1 if not implemented

// you should re-use the UIView that you return here, only initialize it with appropriate values. 
- (UIView *)pageScrollView:(HGPageScrollView *)scrollView headerViewForPageAtIndex:(NSInteger)index;  

- (NSString *)pageScrollView:(HGPageScrollView *)scrollView titleForPageAtIndex:(NSInteger)index;  
- (NSString *)pageScrollView:(HGPageScrollView *)scrollView subtitleForPageAtIndex:(NSInteger)index;  

@end

@protocol HGPageScrollViewDelegate

@optional

// Dragging
- (void) pageScrollViewWillBeginDragging:(HGPageScrollView *)scrollView;
- (void) pageScrollViewDidEndDragging:(HGPageScrollView *)scrollView willDecelerate:(BOOL)decelerate;

// Decelaration
- (void)pageScrollViewWillBeginDecelerating:(HGPageScrollView *)scrollView;
- (void)pageScrollViewDidEndDecelerating:(HGPageScrollView *)scrollView;

// Called before the page scrolls into the center of the view.
- (void)pageScrollView:(HGPageScrollView *)scrollView willScrollToPage:(HGPageView*)page atIndex:(NSInteger)index;

// Called after the page scrolls into the center of the view.
- (void)pageScrollView:(HGPageScrollView *)scrollView didScrollToPage:(HGPageView*)page atIndex:(NSInteger)index;

// Called before the user changes the selection.
- (void)pageScrollView:(HGPageScrollView *)scrollView willSelectPageAtIndex:(NSInteger)index;
- (void)pageScrollView:(HGPageScrollView *)scrollView willDeselectPageAtIndex:(NSInteger)index;

// Called after the user changes the selection.
- (void)pageScrollView:(HGPageScrollView *)scrollView didSelectPageAtIndex:(NSInteger)index;
- (void)pageScrollView:(HGPageScrollView *)scrollView didDeselectPageAtIndex:(NSInteger)index;

@end


よく出来てる。見た目がなかなかいい。


[Info] 写真ライブラリから複数画像を選択できるライブラリ

2011年11月16日水曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加


サンプルの実行例。こんな感じで複数選択できる。

選択結果はデリゲートで受け取れる。
@interface ELCImagePickerController : UINavigationController {

 id delegate;
}

@property (nonatomic, assign) id delegate;

-(void)selectedAssets:(NSArray*)_assets;
-(void)cancelImagePicker;

@end

@protocol ELCImagePickerControllerDelegate

- (void)elcImagePickerController:(ELCImagePickerController *)picker
     didFinishPickingMediaWithInfo:(NSArray *)info;
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;

アルバムの選択用のクラスも用意されている。

@interface ELCAlbumPickerController : UITableViewController {
 
 NSMutableArray *assetGroups;
 NSOperationQueue *queue;
 id parent;
    
    ALAssetsLibrary *library;
}

@property (nonatomic, assign) id parent;
@property (nonatomic, retain) NSMutableArray *assetGroups;

-(void)selectedAssets:(NSArray*)_assets;

@end

悪くない。

[Info] ノンブロッキング/非同期処理ライブラリ - libuv

2011年11月15日火曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

nodejs用に作られたもので WindowsのIOCP、Unix上の libenvをラップしている。Non-blocking TCP sockets や Asynchronous DNS など標準では用意されていない便利な APIが提供されている。

joyent/libuv - GitHub

以下、Features を転載
  • Non-blocking TCP sockets
  • Non-blocking named pipes
  • UDP
  • Timers
  • Child process spawning
  • Asynchronous DNS via c-ares or uv_getaddrinfo.
  • Asynchronous file system APIs uv_fs_*
  • High resolution time uv_hrtime
  • Current executable path look up uv_exepath
  • Thread pool scheduling uv_queue_work
  • ANSI escape code controlled TTY uv_tty_t
  • File system events Currently supports inotify, ReadDirectoryChangesW and kqueue. Event ports in the near future. uv_fs_event_t
  • IPC and socket sharing between processes uv_write2

ネタ元はここ。
iOS 対応のパッチを提供してくれたとのこと。いいね。


[Info] メールアドレスピッカーライブラリ

2011年11月14日月曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

アドレス帳からメールアドレスを取得する簡易ライブラリ。利用しなくてもソースコードが参考になる(かも)。



[Info] BlocksKit

| Published in | 0 コメント

このエントリーをはてなブックマークに追加

Foundation や UIKit ライブラリの様々なクラスのメソッドを blocks 化したライブラリ。 iOS 4.0+ 、 Mac OS X 10.6+ で利用可能。


以下、READMEより転載。

What's In The Box

  • Performing blocks on an NSObject.
  • Key-value observation () with block handlers.
  • Associated objects in an Obj-C API. (Not directly block-related.)
  • NSArray, NSSet, NSDictionary, and NSIndexSet filtering and enumeration.
  • Macros for more quickly typing out the above.
  • NSInvocation creation using a block.
  • NSTimer block execution.
  • Both delegation and block callbacks on NSURLConnection.
  • Delegate callback for NSCache.

UIKit Extensions
  • UIAlertView, UIActionSheet with block callbacks and convenience methods.
  • Block initializers for UIControl and UIBarButtonItem
  • Block-backed initializers for UIGestureRecognizer.
  • On-touch utilities for UIView.
  • Block callbacks for MFMailComposeViewController and MFMessageComposeViewController.
  • Delegate alternative for UIWebView.
これはいい。ちょっとした処理を書くのにいちいちメソッドを起こさなくて済む。本来は Appleが提供して欲しいものだが。
リファレンスマニュアルが appledoc形式で提供されている。
BlocksKit Reference

以下、リファレンスから少し抜粋してみる。

UIActionSheet(BlocksKit)
UIActionSheet *testSheet = [UIActionSheet sheetWithTitle:@"Please select one."];
 [testSheet addButtonWithTitle:@"Zip" handler:^{ NSLog(@"Zip!"); }];
 [testSheet addButtonWithTitle:@"Zap" handler:^{ NSLog(@"Zap!"); }];
 [testSheet addButtonWithTitle:@"Zop" handler:^{ NSLog(@"Zop!"); }];
 [testSheet setDestructiveButtonWithTitle:@"No!" handler:^{ NSLog(@"Fine!"); }];
 [testSheet setCancelButtonWithTitle:nil handler:^{ NSLog(@"Never mind, then!"); }];
 [testSheet showInView:self.view];

NSObject(BlocksKit)
[object performBlock:^(){
  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
} afterDelay:0.5f];


UIGestureRecognizer もある。
UIGestureRecognizer(BlocksKit)
UITapGestureRecognizer *singleTap = [UITapGestureRecognizer recognizerWithHandler:^(id sender) {
     NSLog(@"Single tap.");
 } delay:0.18];
 [self addGestureRecognizer:singleTap];


- - - -
かなり便利なので、いったん使い始めたら以後このライブラリ無しではコーディングできなくなりそうで怖い。。

[Info] 便利メソッドを集めたライブラリ - GHKit

2011年11月11日金曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

便利メソッドをカテゴリで実装しているライブラリ。


appledoc によるリファレンスマニュアルも用意されている。

以下、リファレンスからの転載。


Dates:
GHNSDate+Formatters.h: Date parsers, formatting and formatters for ISO8601, RFC822, HTTP (RFC1123, RFC850, asctime) and since epoch.

 NSDate *date = [NSDate gh_parseISO8601:@"2010-10-07T04:25Z"]
 NSString *dateString = [date gh_formatHTTP]; // Formatted like: Sun, 06 Nov 1994 08:49:37 GMT"

Strings:
GHNSString+Utils.h: Stripping, reversing, counting, UUID, MD5 and more.
 [NSString gh_isBlank:@"  "]; // YES
 [NSString gh_isBlank:nil]; // YES
 [@"abc" gh_reverse]; // @"cba" 
 [@"  some text " gh_strip]; // @"some text"


HMAC:
GHNSString+HMAC.h: SHA-1 HMAC
#import "GTMBase64.h"
["stringtosign" gh_HMACSHA1:@"secret" base64Encoder:[GTMBase64 class]];



組み込んでおくと重宝するかも。

似たようなライブラリでこんなのもあった。
enormego/cocoa-helpers - GitHub

[Info] 設定画面構成ライブラリ - QuickDialog

| Published in | 0 コメント

このエントリーをはてなブックマークに追加

iOS でよく使われているスタイルの設定画面を作成する為のライブラリ。


こんな感じで書ける。
QRootElement *root = [[QRootElement alloc] init];
root.title = @"Hello World";
root.grouped = YES;
QSection *section = [[QSection alloc] init];
QLabelElement *label = [[QLabelElement alloc] initWithTitle:@"Hello" Value:@"world!"];

[root addSection:section];
[section addElement:label];

UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];
これがこうなる。

簡単。

これまで書いてきたコードがたまってきたので似たようなライブラリを作ろうかと思っていた矢先に見つけた。作る前で良かった。。

カスタマイズもできてこんなのも作れるらしい。




[Info] ポップアップウィンドウライブラリ ALPopupView

2011年11月8日火曜日 | Published in | 0 コメント

このエントリーをはてなブックマークに追加

mobilebricksよりポップアップウィンドウ風のビューを提供するライブラリ。有料($19)。




ヘルプ表示などに良さそう。


[Info] カスタムツールバーライブラリ ALToolbar

| Published in | 0 コメント

このエントリーをはてなブックマークに追加

mobilebricks よりカスタムツールバー。有料($19)


見た目は悪くない。


高さ、背景画像のカスタマイズが可能。



人気の投稿(過去 30日間)