作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 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/
我是一名优秀的程序员,十分优秀!