Вопрос

I am sharing a photo to Instagram , some apps insert a tag via photo , how can I do this ?

enter image description here

- (void)instagramWithImage:(UIView*)view openInView:(UIViewController*)viewCont

 {

            UIView* captureView = view;


        /* Capture the screen shoot at native resolution */
        UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, NO, 0.0);
        [captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();


        /* Render the screen shot at custom resolution */
        CGRect cropRect = CGRectMake(0 ,0 ,1024 ,1024);
        UIGraphicsBeginImageContextWithOptions(cropRect.size, NO, 1.0f);
        [screenshot drawInRect:cropRect];
        UIImage * customScreenShot = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();


        NSURL *url;
        docFile.delegate = self;

        //Save image to directory
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.jpg"];


        UIImage *image = customScreenShot;

        NSData *imageData = UIImagePNGRepresentation([image imageByApplyingSharpen3x3]);
        [imageData writeToFile:savedImagePath atomically:NO];

        //load image
        NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.jpg"];
        UIImage *tempImage = [UIImage imageWithContentsOfFile:getImagePath];

        //Hook it with Instagram
        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Image.ig"];
        [UIImageJPEGRepresentation(tempImage, 1.0) writeToFile:jpgPath atomically:YES];

        url = [[NSURL alloc] initFileURLWithPath:jpgPath];
        docFile = [UIDocumentInteractionController interactionControllerWithURL:url];
        [docFile setUTI:@"com.instagram.photo"];

     CGRect rect = viewCont.view.bounds;
        [docFile presentOpenInMenuFromRect:rect inView:viewCont.view animated:YES];



}
Это было полезно?

Решение

You can use the annotation property of the UIDocumentInteractionController to set the caption

documentInteractionController.annotation = @{@"InstagramCaption" : @"yourCustomTag" };

More infos: Instagram Documentation Source

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top