iOS9 – 分享到Instagram(w / hooks)不起作用

我目前正在更新我的应用程序之一,以便与iOS9兼容,并且我在Instagramfunction上遇到了麻烦。 我正在使用他们的开发者网站上陈述的Instagram挂钩:( https://instagram.com/developer/mobile-sharing/iphone-hooks/ )

我希望分享的图像正在成功生成,具有.igo后缀,并且function仍然按iOS8上的预期工作。 它似乎已经打破了新版本的iOS。

以下是使用UIDocumentInteractionController与Instagram分享的代码:

NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { //convert image into .png format. NSData *imageData = UIImagePNGRepresentation(image); //create instance of NSFileManager NSFileManager *fileManager = [NSFileManager defaultManager]; //create an array and store result of our search for the documents directory in it NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create NSString object, that holds our exact path to the documents directory NSString *documentsDirectory = [paths objectAtIndex:0]; //add our image to the path NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //finally save the path (image) [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; CGRect rect = CGRectMake(0 ,0 , 0, 0); UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIGraphicsEndImageContext(); NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"]; NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave]; NSLog(@"jpg path %@",jpgPath); NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath]; NSLog(@"with File path %@",newJpgPath); NSURL *igImageHookFile = [[NSURL alloc]initFileURLWithPath:newJpgPath]; NSLog(@"url Path %@",igImageHookFile); self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; [self.documentController setDelegate:self]; [self.documentController setUTI:@"com.instagram.exclusivegram"]; [self.documentController presentOpenInMenuFromRect:rect inView:self.view animated:YES]; } else { NSLog (@"Instagram not found"); } 

可能值得一提的是,我已经根据iOS9的变化,在info.plist中configuration了URL模式。

UIDocumentInteractionController确实出现,并有“复制到Instagram”选项。 按下这个选项只会导致控制器被解散,在控制器的委托上没有调用日志消息或断点(设置为self;视图控制器)。

如果有人有这个问题,或者遇到了麻烦,听到你的想法,或者更好的解决办法,那将是非常棒的。

更新

另外值得一提的是,在iOS8设备上,文档交互控制器显示“在Instagram中打开”button。 iOS9设备显示“复制到Instagram”button。

改变这行代码后:

 NSURL *igImageHookFile = [[NSURL alloc] initFileURLWithPath:newJpgPath]; 

对此:

 NSURL *igImageHookFile = [NSURL URLWithString:newJpgPath]; 

iOS 9的Instagram共享function正在运行。 看起来,前面的代码行,将NSString转换为NSURL会在URLpath的末尾放置“ – :// file”,这似乎不能很好地与iOS 9兼容。只需将NSString转换为没有初始化为文件URL的NSURL似乎工作。

你必须添加一个新的密钥到你的Info.plist文件中; 这是对URLscheme的iOS 9更改。 看看这个问题的第一个答案: iOS 9不使用URL SCHEME打开Instagram应用程序 。 仅供参考,iOS 9将UIDocumentInteractionController的“Open in Instagram”标题更改为“复制到Instagram”。 不知道为什么。