Post Video on Instagram
I am working on the app where I need to post the image/video on instagram. I have successfully able to post the image on Instagram with following code:
NSString* filename = [NSString stringWithFormat:@"myimage.igo"];
NSString* savePath = [imagesPath stringByAppendingPathComponent:filename];
[UIImagePNGRepresentation(myImage) writeToFile:savePath atomically:YES];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
self.documentInteractionController.UTI = @"com.instagram.image";
self.documentInteractionController.delegate = self;
[self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
But didn't find any way to post the video on it. I checked the Instagram app and found that we can post/upload video too. It means via code It should be possible. Is anyone know about this?
Thanks in advance.
Try this code to post video on instagram it works for me hope it works for you also
first you have to save Video To Cameraroll then use this
NSString *strURL = [NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",yourfilepath,yourCaption];
NSString* webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* instagramURL = [NSURL URLWithString:webStringURL];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
[[UIApplication sharedApplication] openURL:instagramURL];
}
After the deprecation of ALAssetLibrary, Instagram has also disabled the AssetPath parameter. You can now use the localIndentifier property of PHAsset localIndentifier for this case.
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?LocalIdentifier=%@", placeholderForCreatedAsset.localIdentifier]];
[[UIApplication sharedApplication] openURL:instagramURL];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
PS: this works fine for me but it is still not documented anywhere.
链接地址: http://www.djcxy.com/p/19666.html上一篇: 无法用pip安装pycurl
下一篇: 在Instagram上发布视频