我编写了以下代码,用于通过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方法。我能分享它工作正常。但我的问题是在我想重定向到我的应用程序之后。我怎么能这样做或有什么办法吗?
答案 0 :(得分:3)
由于Instagram的独立共享机制,目前无法实现这一目标;您所能做的就是使用内置的共享控制器将您的图像发送到Instagram,然后由用户决定是否切换回您的应用程序。
答案 1 :(得分:0)
在Instagram上发布图片/视频后,无法重定向到您自己的应用程序。因为Instagram没有提供这样的SDK或API,在发布内容后重定向到您的应用程序。用户必须在执行此操作后手动打开应用程序。