照片库中的图像在Instagram中看不到

时间:2015-04-16 14:42:33

标签: ios ios8 instagram phphotolibrary

我有一个应用程序,可以将图像和视频分享给不同的服务。一个是Instagram。由于Instagram不支持直接发送视频,因此我研究了this blog

我能够为使用新照片框架的视频做类似的事情:

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);

     }];

}];

}

0 个答案:

没有答案