我有一个应用程序可以将图像和视频共享到不同的服务。一个是Instagram。由于 Instagram 不支持直接发送视频,我研究了这个博客。
我可以使用新的照片框架为视频做类似的事情:
AVExport to convert to a proper video format.
PHPHotoLibrary > create new album.
PHPHotoLibrary > ad converted asset to the PHLibrary
PHPHotoLibrary > Fetch the PHAsset to get a library URL.
将库 URL 发送到 Instagram。这个过程非常适合视频。但是,我遇到了图像问题!出于某种原因,图像将保存到库中,但它们在 Instagram 中不可见。
任何想法为什么 PhotoLibrary 中的图像在 Instagram 上不可见?在执行 PHLibrary creationRequeest 之前是否有适当的方法来转换图像?
这是我的图像处理的主要片段..
- (void)saveImageAsset:(UIImage*)theImage toAblum:(NSString*)title andCompletion:(void (^)(NSURL* libraryURL))completion {
__block NSString *objIdentifier;
NSData *imgData = UIImagePNGRepresentation(theImage);
theImage = [UIImage imageWithData:imgData];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCollection *assetCollection = [self albumWithTitle:title];
PHAssetChangeRequest* createAssetRequest =
[PHAssetChangeRequest creationRequestForAssetFromImage:theImage];
PHObjectPlaceholder *assetPlaceholder = createAssetRequest.placeholderForCreatedAsset;
PHAssetCollectionChangeRequest *albumChangeRequest =
[PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
[albumChangeRequest addAssets:@[ assetPlaceholder ]];
objIdentifier = assetPlaceholder.localIdentifier;
} completionHandler:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"performChanges Error %@", error);
} else NSLog(@"Write Image Good");
//NSLog(@"objIdentifier = %@", objIdentifier);
PHFetchResult *newFetch = [PHAsset fetchAssetsWithLocalIdentifiers:@[objIdentifier] options:nil];
PHAsset *lastImageAsset = [newFetch lastObject];
// NSLog(@"Image Fetch = %@ --lastImageAsset %@", newFetch, lastImageAsset);
PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
options.synchronous = YES;
options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
options.networkAccessAllowed = NO;
options.version = PHImageRequestOptionsVersionOriginal;
[[PHImageManager defaultManager] requestImageForAsset:(PHAsset *)lastImageAsset
targetSize:CGSizeMake(640,640)
contentMode:PHImageContentModeDefault
options:options
resultHandler:^(UIImage *result, NSDictionary *info) {
//NSLog(@"info = %@", info);
NSURL *finalImageURL = info[@"PHImageFileURLKey"];
NSLog(@"finalImageURL = %@", finalImageURL);
if (!finalImageURL) completion(nil);
completion(finalImageURL);
}];
}];
}