Search code examples
objective-cxcodeinstagraminstagram-api

Instagram story share can't get through login page


I have an app and users are sharing screenshots with it from the app. The app is live and it was working correctly. Nowadays, I realized that when user clicks instagram story share, it goes to login page only. Even the user logins to instagram and re-clicks from my app to share story, it still goes to instagram login page. What is that issue?

- (IBAction)instagramClicked:(id)sender
{
    [FIRAnalytics logEventWithName:@"instagram_share"
                        parameters:@{
                                     @"name": @"instagram_share",
                                     @"full_text": @"instagram_share"
                                     }];

    [self backgroundImage:UIImagePNGRepresentation([self getScreenshot])
           attributionURL:@"abcapp://"];
}

//Get image of the view
- (UIImage *)getScreenshot {
    CGRect rect = [_shareView bounds];
    UIGraphicsBeginImageContextWithOptions(rect.size,NO,2.0f);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [_shareView.layer renderInContext:context];

    UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return capturedScreen;
}

- (void)backgroundImage:(NSData *)backgroundImage
         attributionURL:(NSString *)attributionURL {

    // Verify app can open custom URL scheme, open if able
    NSURL *urlScheme = [NSURL URLWithString:@"instagram-stories://share"];
    if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) {

        // Assign background image asset and attribution link URL to pasteboard
        NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundImage" : backgroundImage,
                                       @"com.instagram.sharedSticker.contentURL" : attributionURL}];
        NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
        // This call is iOS 10+, can use 'setItems' depending on what versions you support
        [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];

        [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
    } else {
        // Handle older app versions or app not installed case
    }
}

Solution

  • This is a bug with the current version of the Instagram app. You have to wait for an update, even their apps like Boomerang are broken when sharing to Instagram.