Save images with phimagemanager to custom album?

后端 未结 5 1531
北荒
北荒 2020-11-28 04:14

I am making an app that takes pictures with AVFoundation and I want to save them to a custom album that I can then query and show in my app. (I\'d prefer to not have them in

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 05:11

    I improved on @ricardopereira and @ColossalChris code. Added video to the extension, and added another extension on top of PHAsset to get rid of the compilation errors. Works in Swift 2.1.

    Sample usage:

    #import "Yourtargetname-Swift.h"//important!
    NSURL *videoURL = [[NSURL alloc] initFileURLWithPath:PATH_TO_VIDEO];
    
    [PHPhotoLibrary saveVideo:videoURL albumName:@"my album" completion:^(PHAsset * asset) {
        NSLog(@"success");
        NSLog(@"asset%lu",(unsigned long)asset.pixelWidth);
    }];
    

    Import both swift files: https://github.com/kv2/PHPhotoLibrary-PhotoAsset.swift

    It is usable in objective-c as long as you import the swift header for your target (see the ViewController.m file).

提交回复
热议问题