Xcode で、iPhone の写真(Camera Roll)を参照する方法

Xcode (iOSアプリ)でiPhoneの写真(Camera Roll)を参照する方法

カメラロールの画面を選択したとき、URLを取得する方法をご紹介します。

スクリーンショット 2016-06-29 16.35.56

mファイルの実装部分
iphoneのカメラロールの写真を使用する場合は、ファイル名でなくURLを使用する。
URLは、文字数が長いので、扱いやすいNSString型に変換する。

1- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
2 
3if ([[segue identifier] isEqualToString:@"showPhoto2"]) {
4 
5    // hand off the assets of this album to our singleton data source
6    [PageViewControllerData sharedInstance].photoAssets = self.assets;
7 
8    NSIndexPath *selectedCell = [self.collectionView indexPathsForSelectedItems][0];
9 
10    ALAsset *asset2 = self.assets[selectedCell.row];
11 
12    NSURL *imageURL = [[asset2 defaultRepresentation] url];
13 
14    //URLをNSString に変換する。
15    NSString *imageURL2 = imageURL.absoluteString;
16    }
17}
Verified by MonsterInsights