Tag: phphotolibrary

如何使用PHPhotoLibrary保存GIF?

我有一个应用程序,显示来自互联网的GIF,我想添加保存GIF到相机胶卷的能力。 我正在使用PHPhotoLibrary ,并试图用我在几个SO问题中看到的方法将它保存到相机胶卷上,例如: func saveToCameraRoll(imageUrl: String) { PHPhotoLibrary.shared().performChanges({ _ in let createRequest = PHAssetChangeRequest.creationRequestForAssetFromImage( atFileURL: URL(string: imageUrl)!) }) { success, error in guard success else { log.debug("failed to save gif \(error)") return } log.debug("successfully saved gif") } } 但是,这让我failed to save gif Optional(Error Domain=NSCocoaErrorDomain Code=-1 "(null)") ,这似乎是由于.gif文件格式,但我找不到另一个如何保存到相机的例子滚动,而不使用已弃用的ALAssetsLibrary.writeImageDataToSavedPhotosAlbum 。 我尝试从Safari中保存一个GIF,这工作:发送给其他人的GIFanimation,所以我知道我想要做什么是可能的,但有人可以指向我的PHPhotoLibrary API的正确部分? 编辑:基于这个答案类似的问题,我想出了如何做我想要的Data和PHAssetCreationRequest如下: class func saveToCameraRoll(imageUrl: String) […]

检测添加照片只有权限

在ios 11中,我们现在有“仅添加照片”权限设置。 但是,我们现在如何确定设置了哪个照片库访问级别? [PHPhotoLibrary authorizationStatus]仅适用于“读取和写入”权限检查。 如果应用程序只要求“仅添加照片”权限,则保持PHAuthorizationStatusNotDetermined 。 如果用户将其从“读写”更改为“仅添加照片”,则会给PHAuthorizationStatusDenied 。 那么,如何判断我的应用程序是否有权限执行“导出到相机胶卷”function,而不需要读取权限呢?

在PHPhotoLibrary中禁用对删除请求的确认

我试图做的是将video保存到PHPhotoLibrary,然后删除它们时,上传到客户端远程服务器在应用程序完成(基本上,照片库作为临时存储添加额外的安全层,以防万一什么都失败了(我已经将我的video保存在应用程序目录中)。 问题: 问题是为了工作,一切都必须工作,没有来自用户的input。 你可以写video到这样的照片库: func storeVideoToLibraryForUpload(upload : SMUpload) { if PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.Authorized { // Don't write to library since this is disallowed by user return } PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in // Write asset let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(NSURL(fileURLWithPath: upload.nonsecureFilePath!)!) let assetPlaceholder = assetRequest.placeholderForCreatedAsset let localIdentifier = assetPlaceholder.localIdentifier // Store local identifier for later use […]

如何从照片,iOS SDK的自定义相册中获取图像?

我正在开发一个iOS应用程序,其中需要像Instagram一样的图库视图。 我已经添加了画廊查看,相机视图和video查看,拍摄后它保存到自定义相册的照片。 现在,我想从自定义相册中检索这些图像,并将其显示到图库的“collections”视图。 但是,我陷入从自定义相册中检索这些图像。 任何帮助将不胜感激。 编辑:我添加了PHPhotoLibrary创build自定义相册,在此之前,我添加了AssetsLibrary框架。 然后,我创build了一个NSObject类(CustomAlbum),用于使用PHPhotoLibrary创build和pipe理自定义相册。 // CustomAlbum.h #import <Foundation/Foundation.h> #import <Photos/Photos.h> @interface CustomAlbum : NSObject //Creating album with given name +(void)makeAlbumWithTitle:(NSString *)title onSuccess:(void(^)(NSString *AlbumId))onSuccess onError: (void(^)(NSError * error)) onError; //Get the album by name +(PHAssetCollection *)getMyAlbumWithName:(NSString*)AlbumName; //Add a image +(void)addNewAssetWithImage:(UIImage *)image toAlbum:(PHAssetCollection *)album onSuccess:(void(^)(NSString *ImageId))onSuccess onError: (void(^)(NSError * error)) onError; //get the image […]

使用新的PHPhotoLibrary保存exif元数据

我目前使用AVCaptureStillImageOutput获得全分辨率的图片。 我也能够使用以下代码获取exif元数据: [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate); CFMutableDictionaryRef mutableDict = CFDictionaryCreateMutableCopy(NULL, 0, metaDict); NSLog(@"test attachments %@", mutableDict); // set the dictionary back to the buffer CMSetAttachments(imageSampleBuffer, mutableDict, kCMAttachmentMode_ShouldPropagate); NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; UIImage *image = [[UIImage alloc] initWithData:imageData]; [self.delegate frameReadyToSave:image withExifAttachments: mutableDict]; }]; 元数据位于mutableDictvariables中。 现在,我想把这张照片保存在两个不同的地方,包括元数据。 […]