iOS SDK 和 Instagram

标签 ios objective-c instagram

在将图像分享到 Instagram 后,有没有办法重新打开我的应用程序?

我分享到 Instagram 的代码:

[Utils saveImage:self.pickedImage withName:@"image.igo"];

CGRect rect = CGRectMake(0 ,0 , 0, 0);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"image.igo"];

NSURL *igImageHookFile = [NSURL fileURLWithPath:imagePath];
self.docFile=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.docFile.UTI = @"com.instagram.exclusivegram";
self.docFile.annotation = [NSDictionary dictionaryWithObject: self.descrText forKey:@"InstagramCaption"];

NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=MEDIA_ID"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [self.docFile presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
}
else {
    [Utils simpleAlertWithTitle:LOC(@"You have not Instagram app in device.") message:nil];
}

现在打开 Instagram 应用程序并打开共享屏幕。 我想在点击 Instagram 应用中的“分享”按钮后返回到我的应用程序,并获取有关共享照片(userId、photoUrl 等)的一些回调。

这可能吗?

谢谢。

最佳答案

Hope this answer will resolve your query. This will directly opens library folder in Instagram instead of Camera.

        NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
        {
            NSURL *videoFilePath = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[request downloadDestinationPath]]]; // Your local path to the video
            NSString *caption = @"Some Preloaded Caption";
            ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
            [library writeVideoAtPathToSavedPhotosAlbum:videoFilePath completionBlock:^(NSURL *assetURL, NSError *error) {
                NSString *escapedString   = [self urlencodedString:videoFilePath.absoluteString];
                NSString *escapedCaption  = [self urlencodedString:caption];
                NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",escapedString,escapedCaption]];
                if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
                    [[UIApplication sharedApplication] openURL:instagramURL];
                }
            }];

关于iOS SDK 和 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21286044/

相关文章:

ios - 无法从 PFObject 获取解析文件

objective-c - 如何实现像 NSArray 这样的自定义对象

html - 在 html img 标签中显示 Instagram 照片

iphone - 将照片导出到 Instagram

api - 我们如何为客户获取实时 Instagram 位置通知?

ios - 当应用程序/ View Controller 离开前台时, Realm 因无效对象而崩溃

objective-c - 如何获得设备的比例因子?

ios - 使用信号量从 Parse 返回图像

ios - 生成带有图像的 UIView

iphone - 如何按整数属性对 CoreData 对象数组进行排序?