簡體   English   中英

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

[英]iOS9 - Sharing to Instagram (w/ hooks) not working

我目前正在更新我的一個應用程序與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");
}

值得一提的是,我已根據iOS9更改的要求在info.plist中配置了URL方案。

UIDocumentInteractionController確實出現,並具有“Copy to Instagram”選項。 按此選項只會導致控制器被解除,控制器的委托上沒有調用日志消息或斷點(設置為self;視圖控制器)。

如果有人或者遇到過這方面的麻煩,那么聽聽你的想法會更好,或者更好的是,它是如何解決的。

更新

值得一提的是,在iOS8設備上,文檔交互控制器顯示“在Instagram中打開”按鈕。 iOS9設備顯示“復制到Instagram”按鈕。

更改此行代碼后:

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

對此:

NSURL *igImageHookFile = [NSURL URLWithString:newJpgPath];  

iOS 9的Instagram共享功能現在正在運行。 似乎前一行代碼,將NSString轉換為NSURL會在URL路徑的末尾放置“ - :// file”,這似乎不能很好地適用於iOS 9.簡單地將NSString轉換為NSURL沒有初始化為文件URL似乎工作。

您必須在Info.plist文件中添加新密鑰; 這是針對URL方案的iOS 9更改。 看看這個問題的第一個答案: iOS 9沒有使用URL SCHEME打開Instagram應用程序 僅舉,僅供參考,iOS 9將UIDocumentInteractionController的“Open in Instagram”標題更改為“Copy to Instagram”。 不知道為什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM