参考情報
Cocoaの日々: [iOS][Mac] dispatch_once を使ったシングルトン
iOS/iPhone/iPad/MacOSX プログラミング, Objective-C, Cocoaなど
2011年11月18日金曜日 | Published in 情報, 情報/2011-11-20, 情報/開発/テクニック | 0 コメント
| Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 0 コメント
AFHTTPClient AFHTTPRequestOperation AFImageCache AFImageRequestOperation AFJSONRequestOperation AFNetworkActivityIndicatorManager AFPropertyListRequestOperation AFURLConnectionOperation AFXMLRequestOperation Protocol References AFMultipartFormData UIImageView(AFNetworking)基本となるHTTPアクセスの他、画像のキャッシュや JSON/XML/PropertyList処理なども用意されている。
// 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: ^(idPOST/マルチパートによるファイルアップロード処理。簡潔でわかりやすい。setUploadProgressBlock: で進捗状況をハンドリング可能。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];
| Published in 情報, 情報/2011-11-20, 情報/開発/プロモーション | 0 コメント
2011年11月17日木曜日 | Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 0 コメント
typedef void (^ReachabilityHandler)(NPReachability *curReach); - (id)addHandler:(ReachabilityHandler)handler; @property (nonatomic, readonly, getter=isCurrentlyReachable) BOOL currentlyReachable; @property (nonatomic, readonly) SCNetworkReachabilityFlags currentReachabilityFlags;
| Published in 情報, 情報/2011-11-20, 情報/開発/iOS5, 情報/開発/チュートリアル | 0 コメント
| Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 0 コメント
HGPageScrollView *pageScrollView = [[[NSBundle mainBundle] loadNibNamed:@"HGPageScrollView" owner:self options:nil] objectAtIndex:0]; [self.view addSubview:pageScrollView];サンプルではページの定義を XIBファイルで行っていた。XIBで定義すれば容易にカスタマイズできる。
@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
2011年11月16日水曜日 | Published in 情報, 情報/2011-11-20, 情報/開発/ツール | 2 コメント
| Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 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;
@end2011年11月15日火曜日 | Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 0 コメント
| Published in 情報, 情報/2011-11-20, 情報/開発/チュートリアル | 0 コメント
imageView.frame = CGRectMake(10.0, 10.0, imageSize.width*1.2, imageSize.height);円形がこのように変形する。
| Published in 情報, 情報/2011-11-20, 情報/開発/iOS5, 情報/開発/チュートリアル | 0 コメント
2011年11月14日月曜日 | Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 0 コメント
| Published in 情報, 情報/2011-11-20, 情報/開発/iOS5 | 0 コメント
| カテゴリ | 用途 | ディレクトリ | バック アップ対象 |
| Critical Data | ユーザが作成するデータ または 再作成ができないデータ | Documents | ◯ |
| Cached Data | 再ダウンロード または 再作成が可能なデータ | Library/Caches | × |
| Temporary Data | 使用期間の短い一時的な データで保存が不要なデータ | tmp | × |
| Offline Data | オフライン時に 利用するデータ | Documents または Library/Private Documents かつ拡張属性付与 | ◯ |
#include <sys/xattr.h>
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
}拡張属性が認識されるのは iOS5.0.1以降。それ以前は機能しない(つまりバックアップされる)。| Published in 情報, 情報/2011-11-20, 情報/開発/ライブラリ | 0 コメント
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];[object performBlock:^(){
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
} afterDelay:0.5f];UITapGestureRecognizer *singleTap = [UITapGestureRecognizer recognizerWithHandler:^(id sender) {
NSLog(@"Single tap.");
} delay:0.18];
[self addGestureRecognizer:singleTap];| Published in 情報, 情報/2011-11-20, 情報/開発/デバッグ | 0 コメント
2011年11月13日日曜日 | Published in 情報, 情報/2011-11-20, 情報/開発/iOS5, 情報/開発/チュートリアル | 0 コメント