1

I have an app that shares images and videos to different services. One being Instagram. Since Instagram does not support sending videos directly I researched this blog.

I was able to do something similar for videos with the new Photos framework:

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.

Send the Library URL to Instagram. This process works great for videos. However, I am having a problem with images! For some reason, the image will save to the library, but they are NOT visible in Instagram.

Any ideas why the image that is in the PhotoLibrary is not viewable Instagram? Is there a proper way to convert the image before doing the PHLibrary creationRequeest?

Here is my main snippet for the image process..

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

     }];

}];

}
Matt Timmons
  • 11
  • 1
  • 4
  • please upload some code snippet – Chirag Shah Apr 16 '15 at 15:23
  • I have noticed that for Instagram, once the photo is uploaded to the device's iCloud Photo library, Instagram will see the image. So, with wifi off (iCloud only uploads photos via wifi) Instagram does not see the Photo asset. Other apps such as HipChat, Faded and more do see it no matter. – Matt Timmons Apr 16 '15 at 16:34
  • Another test: Other images that I add with wifi off (save image to library, screenshots, etc) DO show up as available in Instagram. Pointing to a problem again with how I am saving the asset. – Matt Timmons Apr 16 '15 at 16:41

0 Answers0