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

标签 ios objective-c share instagram social-media

我花了很长时间搜索如何将照片从 iOS 应用程序分享到 Instagram。 Twitter 等其他社交媒体运行良好。我在谷歌上找到了很多资源,但没有用。 请我需要一些帮助来将 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];

提前致谢

最佳答案

您需要使用以下方法:

 -(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", @"")
    }
}

关于ios - objective-c 从我的 iOS 应用程序将图像分享到 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806209/

相关文章:

ios - 当键盘出现时移动可变高度的 TextView

ios - 来自 iOS 静态框架的“无法在 bundle 中加载 NIB”

ios - 在 UIAlertController 中添加复选框

iOS 9.2.1,取消通知不起作用

flutter - MissingPluginException(在 channel plugins.flutter.io/share 上找不到方法共享的实现)

android - 如何制作一个共享我的 res/raw/xxx.mp3 文件的按钮

javascript - 在 iOS 上同时录制和播放(Phonegap 构建)

ios - 如果对象包含基于键的重复名称,则对 json 对象进行分组?

ios - ShareKit 是否仍然有效 - 2015?如果可以,是否可以在 Swift 中实现?

singleton - 如何在两个窗口之间共享单例类的实例