iOS9-与Instagram共享(带有挂钩)不起作用 [英] iOS9 - Sharing to Instagram (w/ hooks) not working

查看:126
本文介绍了iOS9-与Instagram共享(带有挂钩)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在更新我的一个应用程序,使其与iOS9兼容,并且无法共享到Instagram功能.我正在使用开发者网站上所述的Instagram挂钩:( https://instagram.com/developer/mobile-sharing/iphone-hooks/)

I'm currently updating one of my apps to be iOS9 compatible, and I'm having trouble with the share to Instagram function. I'm using the Instagram hooks as stated on their developer site: (https://instagram.com/developer/mobile-sharing/iphone-hooks/)

我希望共享的图像已成功生成,带有.igo后缀,并且该功能仍在iOS8上按预期工作.新版本的iOS似乎已经中断了.

The image I wish to share is being generated successfully, with the .igo suffix, and the functionality is still working as intended on iOS8. It just seems to have broken with the new version of iOS.

以下是使用UIDocumentInteractionController共享到Instagram的代码:

Here's the code for sharing to Instagram, using the UIDocumentInteractionController:

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中配置了URL方案.

It's probably worth mentioning I've already configured the URL schemes in the info.plist as required with the iOS9 changes.

UIDocumentInteractionController确实出现,并且具有复制到Instagram"选项.按下此选项只会导致控制器被解雇,不会在控制器的代表(设置为self;视图控制器)上调用任何日志消息或断点.

The UIDocumentInteractionController does appear, and has the option 'Copy to Instagram'. Pressing this option just leads to the controller being dismissed, with no log messages or breakpoints being called on the controller's delegate (set to self; the view controller).

如果有人对此有问题或遇到麻烦,很高兴听到您的想法,或者更好的是,它是如何解决的.

If anyone has, or has had trouble with this, it would be great to hear your thoughts, or better yet, how it was solved.

更新

值得一提的是,在iOS8设备上,文档交互控制器显示了在Instagram中打开"按钮. iOS9设备显示复制到Instagram"按钮.

It's also worth mentioning, on an iOS8 device, the Document Interaction Controller shows an 'Open in Instagram' button. The iOS9 device shows a 'Copy to Instagram' button.

推荐答案

更改此行代码后:

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

对此:

NSURL *igImageHookFile = [NSURL URLWithString:newJpgPath];  

iOS 9的Instagram共享功能现在可以使用.似乎将NSString转换为NSURL的上一行代码会将-://file"放在URL路径的末尾,这似乎无法在iOS 9上很好地注册.只需将NSString转换为未初始化为文件URL的NSURL似乎可以正常工作.

The Instagram-share function for iOS 9 is now working. It seems that the previous line of code, converting the NSString to an NSURL would place "--://file" at the end of the URL path, which doesn't seem to register well with iOS 9. Simply converting the NSString to NSURL without initialising as a file URL seems to work.

这篇关于iOS9-与Instagram共享(带有挂钩)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆