使用他们的iOS挂钩发布照片到Instagram
我在我的iOS应用程序中使用以下代码来使用Instagram iPhone挂钩将照片发布到Instagram。 我只想要“打开在…”菜单有Instagram的应用程序,没有其他的应用程序。 但在我的情况下,相机+也出现了。 我怎样才能限制到Instagram?
另外,我可以直接打开Instagram,而不是显示打开菜单吗?
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { //imageToUpload is a file path with .ig file extension self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imageToUpload]]; self.documentInteractionController.UTI = @"com.instagram.photo"; self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"my caption" forKey:@"InstagramCaption"]; [self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.exportBarButtonItem animated:YES]; }
要回答您的第一个问题:您可能可以限制“打开在…”菜单,只显示您的设备的Instagram(例如通过删除相机+应用程序),但您将无法限制将您的应用安装到他们的设备的用户。 这是因为iPhone识别哪些应用程序能够打开特定types的文件,并自动显示每个文件。
顺便说一句Instagram增加了一个独家文件扩展(ig)和UTI(com.instagram.exclusivegram)。 它仍然打开“打开…”菜单,但唯一的select是Instagram。
更多信息在这里: https : //instagram.com/developer/mobile-sharing/iphone-hooks/
你可以从这个链接获得解决scheme。
-
使用
.igo
扩展名而不是.igo
保存图像。 这是filetype的“独占”版本。 -
创build一个
UIDocumentInteractionController
,然后将值com.instagram.exclusivegram
分配给属性UTI
。 -
用
presentOpenInMenuFromRect:inView:animated
你的UIDocumentInteractionController
presentOpenInMenuFromRect:inView:animated
。
这工作对我来说,这样做,你将只有Instagram作为独家应用程序来打开你的形象。
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];
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self]; self.documentInteractionController=[UIDocumentInteractionController interactionControllerWithURL:imgurl]; self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
以相同的顺序使用此代码。 这里documentInteractionController是UIDocumentInteractionController.just的对象。 您只会在“打开”窗口中获取instagram。