Post photo to Instagram using their iOS hooks

白昼怎懂夜的黑 提交于 2019-11-30 04:05:24

To answer only your first question: you may probably be able to restrict the "Open in ..." menu to just showing Instagram for your device (by deleting the Camera+ App, for example), but you won't be able to restrict users that install your app to their devices. And that's because the iPhone recognizes which applications are able to open a specific kind of files and it automatically show every one that does.

JoshOiknine

BTW Instagram added an exclusive file extention (ig) and UTI (com.instagram.exclusivegram) for this. It still opens the Open with... menu but the only option is Instagram.

More info here: https://instagram.com/developer/mobile-sharing/iphone-hooks/

nahung89

You can get the solution from this link.

  1. Save image with the .igo extension instead of .ig. This is the "exclusive" version of the filetype.

  2. Create a UIDocumentInteractionController, then assign the value com.instagram.exclusivegram to the property UTI.

  3. Present your UIDocumentInteractionController with presentOpenInMenuFromRect:inView:animated.

This worked for me, do it like this and you will have only Instagram as the exclusive app to open your image.

    NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    // *.igo is exclusive to instagram
    NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"];
    NSData *imageData = UIImagePNGRepresentation(filteredImage);
    [imageData writeToFile:saveImagePath atomically:YES];

    NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];

    _docController=[[UIDocumentInteractionController alloc]init];
    _docController.delegate=self;
    _docController.UTI=@"com.instagram.photo";
    [_docController setURL:imageURL];
    _docController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:@"#yourHashTagGoesHere",@"InstagramCaption", nil];
    [_docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
utkal patel
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];

self.documentInteractionController=[UIDocumentInteractionController  interactionControllerWithURL:imgurl];

self.documentInteractionController.UTI = @"com.instagram.exclusivegram";

use this code in same sequence . here documentInteractionController is object of UIDocumentInteractionController.just for your knowledge. you will get instagram only in "open in" window.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!