Instagram分享

来源:互联网 发布:航班数据 编辑:程序博客网 时间:2024/04/30 17:36

分享图片

The answer is that it is not pulling the video from the camera roll at all, it might just look like it is.

Documentation here: http://instagram.com/developer/mobile-sharing/iphone-hooks/

The relevant bit is the bottom section "Document Interaction".

You would do this by doing something like this:

NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"instagram.igo"];NSData *data = // set this yourselfNSError *error = nil;if (! [data writeToFile:filePath options:NSDataWritingAtomic error:&error]){    // error here}self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];self.documentInteractionController.delegate = self;self.documentInteractionController.UTI = @"com.instagram.exclusivegram";self.documentInteractionController.annotation = @{ @"InstagramCaption" : @"caption text here" };const BOOL couldOpen = [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:myView animated:YES];

Set the data, the caption, and the view to present from yourself. Notice the UIDocumentInteractionController is also a property. It should be retained somewhere and not just a local variable in a method because it needs to exist outside of that scope when the method completes.



分享视频

 


- (void)shareVideoWithInstagram {

[assetsLibrary writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:videoPath] completionBlock:^(NSURL *assetURL, NSError *error) {

NSString *caption =@"Your caption";

    NSURL *instagramURL = [NSURLURLWithString:[NSStringstringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",

                                                [[assetURLabsoluteString] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetalphanumericCharacterSet]],

                                                [captionstringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetalphanumericCharacterSet]]]

                           ];

    if ([[UIApplicationsharedApplication] canOpenURL:instagramURL]) {

        [[UIApplication sharedApplication] openURL:instagramURL];

    }

   

}


0 0