Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram InstagramCaption not working

I have below code for sharing article on Instagram.

-(void) shareInstagram {
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
    if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not
    {
        UIImage *instaImage = mImg.image;
        NSData *imageData = UIImagePNGRepresentation(instaImage); //convert image into .png format.
        NSLog(@"imageData.leeee===%d", imageData.length);
        if (imageData.length<=100) {
            [self.view makeToast:localize(@"instaErr2") duration:2.0 position:@"bottom"];
        } else {
            NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
            NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
            NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //add our image to the path
            [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
            NSLog(@"image saved");

            CGRect rect = CGRectMake(0 ,0 , 0, 0);
            UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
            [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
            UIGraphicsEndImageContext();
            NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"];
            NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave];
            NSLog(@"jpg path %@",jpgPath);
            NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath];
            NSLog(@"with File path %@",newJpgPath);
            NSURL *igImageHookFile = [[NSURL alloc]initFileURLWithPath:newJpgPath];
            NSLog(@"url Path %@",igImageHookFile);

            self.documentController.UTI = @"com.instagram.exclusivegram";
            self.documentController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
            self.documentController=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];

            NSString *globalString;

            if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"PoPinFrom"] isEqualToString:@"user"]) {
                globalString = [NSString stringWithFormat:@"%@ @ %@\n\nhttp://egkw.com/ArticleDetail.aspx?id=%@\n\niPhone : %@\n\nAndroid : %@", [[productDetailsArray objectAtIndex:0] valueForKey:@"Title"], localize(@"appName"), [[productDetailsArray objectAtIndex:0] valueForKey:@"Id"], localize(@"appStoreLink"), localize(@"playStoreLink")];
            } else {
                globalString = [NSString stringWithFormat:@"%@ @ %@\n\nhttp://egkw.com/ArticleDetail.aspx?id=%@\n\niPhone : %@\n\nAndroid : %@", [[productDetailsArray objectAtIndex:0] valueForKey:@"Title"], localize(@"appName"), [[productDetailsArray objectAtIndex:0] valueForKey:@"Id"], localize(@"appStoreLink"), localize(@"playStoreLink")];
            }

            globalString = [NSString stringWithFormat:@"%@\n\n#EGKW", globalString];
            NSLog(@"insta==globalString==%@", globalString);
            self.documentController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:globalString, @"InstagramCaption", nil];
            // self.documentController.annotation = [NSDictionary dictionaryWithObject:globalString forKey:@"InstagramCaption"];
            [self.documentController presentOpenInMenuFromRect:rect inView: self.view animated:YES];
        }
    }
    else
    {
        NSLog (@"Instagram not found");
        DTAlertView *myAl = [DTAlertView alertViewWithTitle:localize(@"err001") message:localize(@"instaErr") delegate:nil cancelButtonTitle:localize(@"dismiss") positiveButtonTitle:nil];
        [myAl setDismissAnimationWhenButtonClicked:DTAlertViewAnimationSlideTop];
        [myAl showWithAnimation:DTAlertViewAnimationSlideBottom];
    }
}

This code was working fine earlier. However when I noticed, I see that caption is not showing in Instagram. After research I changed

 self.documentController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:globalString, @"InstagramCaption", nil];

to

self.documentController.annotation = [NSDictionary dictionaryWithObject:globalString forKey:@"InstagramCaption"];

But still it is not working.

Any idea what is going wrong?

Did Instagram changed any policy like Facebook?

like image 810
Fahim Parkar Avatar asked Aug 10 '15 08:08

Fahim Parkar


People also ask

Why can't I write captions on Instagram?

Instagram app for Android and iPhone Tap or your profile picture in the bottom right to go to your profile. Tap in the top right, then tap Settings. Tap Account, then tap Captions. Tap or next to Captions to turn them on or off.

Why can't I find Caption sticker on Instagram?

If you're not seeing certain stickers on Instagram, make sure your app is updated to the latest version by visiting the App Store or Google Play Store. Keep in mind that not all stickers are available to everyone or available for reels.

How do I turn on auto generate caption on Instagram?

Users can turn the auto-generated captions on or off by going into their advanced settings in the app and toggling the “show captions” option. Instagram notes that the AI behind the captions will continue to improve as it learns.


1 Answers

Instagram has now removed the filling in of the caption field using the interaction controller.

See this blog post from them

Instagram developer blog

like image 130
AndyRyan Avatar answered Oct 25 '22 00:10

AndyRyan