Aqlier/ 6月 29, 2016/ iPhone

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

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

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

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


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([[segue identifier] isEqualToString:@"showPhoto2"]) {

    // hand off the assets of this album to our singleton data source
    [PageViewControllerData sharedInstance].photoAssets = self.assets;

    NSIndexPath *selectedCell = [self.collectionView indexPathsForSelectedItems][0];

    ALAsset *asset2 = self.assets[selectedCell.row];

    NSURL *imageURL = [[asset2 defaultRepresentation] url];

    //URLをNSString に変換する。
    NSString *imageURL2 = imageURL.absoluteString;
    }
}