【问题标题】:How can redirect to my iOS application from instagram app after share分享后如何从 Instagram 应用重定向到我的 iOS 应用
【发布时间】:2015-08-21 04:55:52
【问题描述】:

我编写了以下代码来通过 instagram 共享图像。它工作正常,但我的问题是我想在共享完成后重定向到我的应用程序。

 -(void)instaGramWallPost
{
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not
{

    UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, self.view.frame.size.height));
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
    NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
    NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //add our image to the path
    [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
    NSLog(@"image saved");

    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.UTI = @"com.instagram.exclusivegram";
    self.documentController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
    self.documentController=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    [self.documentController presentOpenInMenuFromRect:rect inView: self.view animated:YES];
}
else
{
    [[[UIAlertView alloc]initWithTitle:@"Title" message:@"Please install instagram and try again" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] show];
}
}

-(UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate      {

UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;
return interactionController;
}

我会在需要时调用 instagramWallPost 方法。我可以分享它工作正常。但我的问题是在那之后我想重定向到我的应用程序。我该怎么做或者有什么办法可以做到这一点?

【问题讨论】:

    标签: ios objective-c iphone ios7 instagram


    【解决方案1】:

    由于 Instagram 的独立分享机制,目前无法实现;您所能做的就是使用内置的共享控制器将您的图像发送到 Instagram,然后由用户决定是否切换回您的应用程序。

    【讨论】:

      【解决方案2】:

      在 Instagram 上发布图像/视频后,无法重定向到您自己的应用程序。因为 Instagram 没有提供这样的 SDK 或 API,可以在发布内容后重定向到您的应用程序。执行此操作后,用户必须手动打开应用程序。

      【讨论】:

        猜你喜欢
        • 2013-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多