目前,我正在更新我的一个应用程序,使其与iOS9兼容,而且我在分享Instagram功能方面遇到了困难。我正在使用Instagram钩子,正如他们的开发者网站上所述:(https://instagram.com/developer/mobile-sharing/iphone-hooks/)
我希望共享的映像正在成功地生成,并带有.igo后缀,该功能仍在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");
}
可能值得一提的是,我已经根据需要在info.plist中配置了iOS9更改中的URL方案。
UIDocumentInteractionController确实出现了,并且有‘复制到Instagram’的选项。按此选项只会导致关闭控制器,没有在控制器的委托上调用日志消息或断点(设置为self;视图控制器)。
如果有人在这件事上有问题,听到你的想法,或者更好的是,它是如何被解决的,那就太好了。
更新
值得一提的是,在iOS8设备上,文档交互控制器()显示了一个‘’按钮。iOS9设备显示一个“复制到Instagram”按钮。
发布于 2015-09-16 18:43:59
更改这一行代码后:
NSURL *igImageHookFile = [[NSURL alloc] initFileURLWithPath:newJpgPath];
对此:
NSURL *igImageHookFile = [NSURL URLWithString:newJpgPath];
iOS 9的Instagram共享功能现在正在运行。上一行代码(将NSString转换为NSURL )似乎会将“-:// file”放在URL路径的末尾,而iOS 9似乎没有很好地注册。简单地将NSString转换为NSURL而不初始化为文件URL似乎是可行的。
发布于 2015-09-27 21:18:50
您必须向您的Info.plist文件中添加一个新密钥;这是对iOS方案的iOS 9更改。请查看这个问题的第一个答案:iOS 9 not opening Instagram app with URL SCHEME。iOS 9将UIDocumentInteractionController的“Instagram开放”更改为“复制到Instagram”。不知道为什么。
https://stackoverflow.com/questions/32593908
复制相似问题