Swift UIImagePickerControllerでカメラの画像を取得するサンプル

UIImagePickerControllerでカメラの画像を取得するサンプルこれもシンプルな実装で完結できる。

f:id:loosefingers:20160806215608p:plain

作ってみたコードはこちら、赤いボタンを押すと写真が選択され画面に表示される。すこし気をつける部分は以下の設定も必要。

UINavigationControllerDelegate

今回のサンプルコード gist.github.com

念のため、didFinishPickingMediaWithInfo後のInfoの中の情報は以下のようになっている。

[
"UIImagePickerControllerCropRect": NSRect: {{0, 0}, {1280, 962}},
"UIImagePickerControllerOriginalImage": <UIImage: 0x161232410> size {1280, 960} orientation 0 scale 1.000000, "UIImagePickerControllerReferenceURL": assets-library://asset/asset.JPG?id=DA1FE337-C6AD-43D7-8AE5-3C4303249428&ext=JPG, 
"UIImagePickerControllerMediaType": public.image, 
"UIImagePickerControllerEditedImage": <UIImage: 0x16121dbb0> size {1239, 930} orientation 0 scale 1.000000
]