gpt4 book ai didi

ios - 使用 iPhone Hooks 将图片/视频从照片上传到 Instagram

转载 作者:行者123 更新时间:2023-11-29 12:21:13 25 4
gpt4 key购买 nike

我想使用 iPhone Hooks 将图片和视频上传到 Instagram但无法达到结果。

对于视频,我使用以下代码:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library writeVideoAtPathToSavedPhotosAlbum:videoFilePath completionBlock:^(NSURL *assetURL, NSError *error)
{
NSString *CFURL = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)[NSString stringWithFormat:@"%@", [assetURL absoluteString]], NULL, CFSTR("!$&'()*+,-./:;=?@_~"), kCFStringEncodingUTF8));

NSString *CFCaption = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)[NSString stringWithFormat:@"%@", strInstagramCaption], NULL, CFSTR("!$&'()*+,-./:;=?@_~"), kCFStringEncodingUTF8));

NSString *instagramString = [NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@", [assetURL absoluteString], strInstagramCaption];
NSLog(@"instagramString : %@", instagramString);

NSURL *instagramURL = [NSURL URLWithString:instagramString];
NSLog(@"instagramURL : %@", instagramURL);

if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
[[UIApplication sharedApplication] openURL:instagramURL];
}

}];

最佳答案

这是使用 URI 在 Instagram 上分享图片的代码。

@property (nonatomic, retain) UIDocumentInteractionController *dic;    

CGRect rect = CGRectMake(0 ,0 , 0, 0);
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndImageContext();
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];

NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
self.dic.UTI = @"com.instagram.photo";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
[self.dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ];


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

您也可以从here 下载示例项目。 .

关于ios - 使用 iPhone Hooks 将图片/视频从照片上传到 Instagram,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568086/

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