gpt4 book ai didi

iphone - 如何将图像从我们的应用程序导出到 Instagram?

转载 作者:可可西里 更新时间:2023-11-01 06:18:29 25 4
gpt4 key购买 nike

我使用了以下代码,但没有用。我想将我的应用程序中的图像放到我的 iPhone 上安装的 Instagram 应用程序中。

NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:@"IMG_0192"  ofType:@"jpg"];
fileToOpen = [fileToOpen substringToIndex:[fileToOpen length] - 3];
fileToOpen=[NSString stringWithFormat:@"%@ig",fileToOpen];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
NSLog(@"%@",fileToOpen);
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
/*UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@""
message:@"Can open app!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
*/

self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
self.documentInteractionController.UTI = @"com.instagram.photo";
self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Its a testing" forKey:@"InstagramCaption"];

我尝试了很多,但它根本不起作用。

最佳答案

您可以使用以下代码将图像从您的应用分享到您 iPhone 上安装的 Instagram 应用。

- (void) shareImageToInstagram 
{
NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
CGRect rect = CGRectMake(0,0,0,0);
CGRect cropRect=CGRectMake(0,0,612,612);
NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
CGImageRef imageRef = CGImageCreateWithImageInRect([imgViewPost.image CGImage], cropRect);
UIImage *img = [[UIImage alloc] initWithCGImage:imageRef];
CGImageRelease(imageRef);

[UIImageJPEGRepresentation(img, 1.0) writeToFile:jpgPath atomically:YES];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",jpgPath]];
self.dicont.UTI = @"com.instagram.photo";
self.dicont = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dicont.annotation = [NSDictionary dictionaryWithObject:@"Your AppName" forKey:@"InstagramCaption"];
[self.dicont presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
else
{
DisplayAlert(@"Instagram not installed in this device!\nTo share image please install instagram.");
}
}

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
interactionController.delegate = interactionDelegate;

return interactionController;
}

请尝试此代码..

关于iphone - 如何将图像从我们的应用程序导出到 Instagram?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14707642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com