Iphone 在ios中共享instagram上的图像
我有一个在instagram上分享图片的应用程序,它运行得非常好 如屏幕截图所示。当我按下instagram上的“共享”按钮时,它会在UIActivityviewcontroller中打开 如果我点击Instagram上的共享并直接进入Instagram原生应用程序,是否可能 如果用户的设备中安装了其他应用程序,这些应用程序也会因为UIActivityViewController而显示 我不想让UIActivityviewcontroller显示“在Instagram中打开” 提前谢谢 已编辑 我正在拍摄一个视图截图,并在Instagram上分享该截图 当我点击“共享”按钮时,它会打开,如屏幕截图所示,这是我不想要的 我正在使用下面的代码Iphone 在ios中共享instagram上的图像,iphone,ios,objective-c,instagram,Iphone,Ios,Objective C,Instagram,我有一个在instagram上分享图片的应用程序,它运行得非常好 如屏幕截图所示。当我按下instagram上的“共享”按钮时,它会在UIActivityviewcontroller中打开 如果我点击Instagram上的共享并直接进入Instagram原生应用程序,是否可能 如果用户的设备中安装了其他应用程序,这些应用程序也会因为UIActivityViewController而显示 我不想让UIActivityviewcontroller显示“在Instagram中打开” 提前谢谢 已编辑
NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
imagename=[NSString stringWithFormat:@"ff.ig"];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imagename];
////NSLog(@"%@",fullPathToFile);
igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", fullPathToFile]];
self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.dic.annotation = [NSDictionary dictionaryWithObject:@"Image" forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect: rect inView:self.view animated: YES ];
}
你检查过你的图像大小了吗?因为它支持大于612*612的图像,所以请检查你正在发布的图像的大小
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];
self.documentInteractionController=[UIDocumentInteractionController interactionControllerWithURL:imgurl];
self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
按相同顺序使用此代码。这里documentInteractionController是UIDocumentInteractionController的对象。仅供参考。您只能在“打开”窗口中获得instagram
使用igo扩展名而不是ig保存图像
这样,您只能在“打开”菜单中获得instagram选项
或者,如果您想在按下按钮时直接打开instagram,您可以传递应用程序的直接url,它将引导您进入本机instagram应用程序
希望对你有帮助 对于swift
var instagramURL = NSURL(string: "instagram://app")!
if UIApplication.sharedApplication().canOpenURL(instagramURL) {
var documentDirectory = NSHomeDirectory().stringByAppendingPathComponent("Documents")
var saveImagePath = documentDirectory.stringByAppendingPathComponent("Image.igo")
var imageData = UIImagePNGRepresentation(self.bestScoreShareView.takeSnapshot(W: 640, H: 640))
imageData.writeToFile(saveImagePath, atomically: true)
var imageURL = NSURL.fileURLWithPath(saveImagePath)!
docController = UIDocumentInteractionController()
docController.delegate = self
docController.UTI = "com.instagram.exclusivegram"
docController.URL = imageURL
docController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
} else {
println("instagram not found")
}
从uiview拍摄形状快照的扩展
设置图像大小的扩展
谢谢你的回复,但我的图片分享成功,但我想分享没有“在instagram中打开”的图片是可能的吗?当图像共享成功时,如何重定向到我的应用程序?是的,您可以在if语句中使用上述代码中的[[UIApplication sharedApplication]canOpenURL:instagramURL]行直接转到本机instagram应用程序。然后您将被重定向到本机应用程序。一旦您转到本机instagram应用程序,就无法重定向到您的应用程序。你必须再次打开你的应用程序。好的,但instagramURL是什么?我尝试了NSURL*instagramURL=[NSURL URLWithString:@“instagram://”;但没有打开本机instagram应用程序,只需查看我上面的代码即可。你可以看到。只需在if之后添加一行[[UIApplication sharedApplication]canOpenURL:instagramURL],它将直接打开instagram应用程序。令人印象深刻的扩展!
extension UIView {
func takeSnapshot(#W: CGFloat, H: CGFloat) -> UIImage {
var cropRect = CGRectMake(0, 0, 600, 600)
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
image.imageWithNewSize(CGSizeMake(W, H))
return image
}
}
extension UIImage {
func imageWithNewSize(newSize:CGSize) ->UIImage {
UIGraphicsBeginImageContext(newSize)
self.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
let newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage
}
}