2008年6月13日金曜日

1-06 Using iPhone Features in Your Application.m4v

ビデオのメモ

iPhoneのアプリケーションはアドレス帳や写真からデータにアクセスできます。また、Webの内容をアプリケーション内に埋め込むこともできます。
アドレス帳のアクセス方法
既存のデータ利用
 ABPeoplePickerNavigationController
 ABPersonViewController
データ生成
 ABNewPersonViewController
未処理データの扱い
 ABUnknownPersonViewController
データの読み書き
 ABAddressBookCopyPeopleWithName
 ABPersonCopyImageData
 ABPersonCreate
 ABRecordSetValue
注意事項
 CFRetaiとCFReleaseを使用すること
 CopyとCreateを使用したときは必ず解放すること
 Getは自身でメモリを確保していないらしく、解放する必要がないらしい

写真のアクセス方法
iPhoneやiPod touchの写真ライブラリから写真を表示する方法

// 写真ライブラリが空でないことを確認
if ([UIImagePickerController isSourceTypeAvailable:
 UIImagePickerControllerSourceTypePhotoLibrary]) {

 UIImagePickerController *picker;
 picker = [[UIImagePickerController alloc] init];
 picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

 picker.allowsImageEditing = YES;

 picker.delegate = self;

 [currentViewController presentModalViewController:picker animated:YES];
}

カメラは上記のソースを少し変更するだけで利用できます。
// 写真ライブラリが空でないことを確認
if ([UIImagePickerController isSourceTypeAvailable:
 UIImagePickerControllerSourceTypeCamera]) { // Cameraになっています

 UIImagePickerController *picker;
 picker = [[UIImagePickerController alloc] init];
 picker.sourceType = UIImagePickerControllerSourceTypeCamera; // Cameraになっています

 picker.allowsImageEditing = YES;

 picker.delegate = self;

 [currentViewController presentModalViewController:picker animated:YES];
}

写真の編集
元になる関数は以下の通りです。
- (void) imagePickerController:(UIImagePickerController *) picker
     didFinishPickingImage:(UIImage *) imagePickerController
           editingInfo:(NSDictionary *) editingInfo {
// 必要に応じてイメージを処理
 [self saveImage;image];
}

例です。

- (void) imagePickerController:(UIImagePickerController *) picker
     didFinishPickingImage:(UIImage *) image
           editingInfo:(NSDictionary *)editingInfo{

// 元のイメージを入手
 UIImage *origialImage = [editingInfo
           valueForKey:UIImagePickerControllerOriginalImage];

// メタデータとして保存
 [self saveTagZone:[editingInfo
    valueForKey:UIImagePickerControllerCropRect]];
}

Webの内容を入手

// Web viewを生成
 CGRect rect = [[UIScreen mainScreen] appicationFrame];
 UIWebView *webView = [[UIWebView alloc] initWithFrame:rect];

// 電話番号の検出機能を切る
 webView.detectsPhoneNumbers = NO;

// Web viewURLをロード
 NSURL url = [NSURL URLWithString:@"http://foo.com"];
 NSURLRequest *req = [NSURLRequest requestWithURL:url];
 [webView loadRequest:req];

以下の方法でURLを開く感覚で他のアプリケーションを開くこともできると言っています。


 NSURL *url = [NSURL URLWithString:@"http://apple.com"];
 [[UIApplication sharedApplication] openURL:url];

URLに応じて以下のアプリケーションを開くことができると言っています。
 Safari:http://, https://, feed://
 Mail;mailto:
 Google Map:http://maps.google.com/
 You Tube:http://www.youtube.com/
 iTunes:itms://
独自アプリケーション:myapp://

独自アプリケーションをURLで起動できるようにするにはinfo.plistに以下の項目を追加します。
CFBundleURLType      Array
 0            Dictionary
  CFBundleURLName   String My Custom URL
  CFBundleURLSchemes  Array
   0           String myapp
  LSIsAppleDeaultForScheme Boolean Yes

- (BOOL)application:(UIApplication *) application
 handleOpenURL:(NSURL *) uel {
// 送られてきた問い合わせの文字列を入手
 NSString *queryString = [url query];

// 送られてきた文字列から情報を取得...

//キーと値を処理 ...
}

他のiPhoneとの通信
Bonjour
を使用して通信できるとしていますが、消費電力が増大し電池使用時間が短くなる、とも言っています。

0 件のコメント:

Open Source

Appleが主催するdarwin-devのMailing listにAppleのDarwin TeamのWilliam SiegristがDeveloper Tools 3.1.3とiPhone OS 3.0関連のソース一部を公開したと投稿していました。 Developer To...