objective-c从我的iOS应用程序中分享到Instagram的图像

时间:2016-11-25 13:30:49

标签: ios objective-c share instagram social-media

我花了很长时间搜索如何将照片从iOS应用程序分享到Instagram。像Twitter这样的其他社交媒体工作正常。我在Google上找到了很多资源,但它没有用。 我需要一些帮助才能将Instagram分享按钮添加到已经拥有Twitter分享按钮的UIActivityViewController。 这是我的代码:

- (IBAction)shareBtnClicked {
    NSString *textToShare = @"Share \r";
    NSURL *url = newsC.URL;
    NSArray *objectsToShare = @[textToShare, url];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

    //this array should add the activities that I don’t want
    NSArray *excludeActivities = @[ UIActivityTypePrint,
                                    UIActivityTypeAssignToContact,
                                    UIActivityTypePostToFlickr,
                                    UIActivityTypePostToVimeo
                                    ];

    activityVC.excludedActivityTypes = excludeActivities;
    [self presentViewController:activityVC animated:YES completion:nil];

提前致谢

2 个答案:

答案 0 :(得分:2)

您需要使用以下方法:

 -(void)instaPostImage
    {
        NSURL *myURL = [NSURL URLWithString:@"Your image url"];
        NSData * imageData = [[NSData alloc] initWithContentsOfURL:myURL];
        UIImage *imgShare = [[UIImage alloc] initWithData:imageData];

        NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];

        if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not
        {
            UIImage *imageToUse = imgShare;
            NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
            NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.png"];
            NSData *imageData=UIImagePNGRepresentation(imageToUse);
            [imageData writeToFile:saveImagePath atomically:YES];
            NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
            self.documentController=[[UIDocumentInteractionController alloc]init];
            self.documentController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
            self.documentController.delegate = self;
            self.documentController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Testing"], @"InstagramCaption", nil];
            self.documentController.UTI = @"com.instagram.exclusivegram";
            UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
            [self.documentController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:vc.view animated:YES];
    }
    else {
        DisplayAlertWithTitle(@"Instagram not found", @"")
    }
}

答案 1 :(得分:1)

试试这个

ForeignKey

}