ãã¹ã 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ã®è§£èª¬è¨äº。