分享facebook.分享instagram其他代码

分享到instagram.一般只能分享图片.但是需要分享视频文件.就将数据加载到本地然后再分享出去.视频有长度限制60s以内才行
-(void)instaGramWallPostWithURL:(NSString *)url { NSURL *myURL = [NSURL URLWithString:@"一个视频url"]; NSData * imageData = [[NSData alloc] initWithContentsOfURL:myURL]; // UIImage *imgShare = [[UIImage alloc] initWithData:imageData]; NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not { // UIImage *imageToUse = imgShare; NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; // NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.igo"]; NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Video.mp4"]; // NSData *imageData=UIImagePNGRepresentation(imageToUse); [imageData writeToFile:saveImagePath atomically:YES]; NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath]; self.documentController=[[UIDocumentInteractionController alloc]init]; self.documentController = [UIDocumentInteractionController interactionControllerWithURL:imageURL]; self.documentController.delegate = self; self.documentController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Testing"], @"InstagramCaption", nil]; self.documentController.UTI = @"com.instagram.exclusivegram"; UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController; [self.documentController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:vc.view animated:YES]; } else { NSLog(@"Instagram not found"); } }

分享到facebook.系统自带api分享: 引入头文件< Social.h>
/* *****可以分享的平台*****
SOCIAL_EXTERN NSString *const SLServiceTypeTwitter NS_AVAILABLE(10_8, 6_0)
SOCIAL_EXTERN NSString *const SLServiceTypeFacebook NS_AVAILABLE(10_8, 6_0);
SOCIAL_EXTERN NSString *const SLServiceTypeSinaWeibo NS_AVAILABLE(10_8, 6_0);
SOCIAL_EXTERN NSString *const SLServiceTypeTencentWeibo NS_AVAILABLE(10_9, 7_0);
SOCIAL_EXTERN NSString *const SLServiceTypeLinkedIn NS_AVAILABLE(10_9, NA);
*/
if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { NSLog(@"不可用"); return; }

  `  // 创建控制器,并设置ServiceType
    SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];`
    // 添加要分享的图片
    [composeVC addImage:[UIImage imageNamed:@"Nameless"]];
    // 添加要分享的文字
    [composeVC setInitialText:@"share to PUTClub"];
    // 添加要分享的url
    [composeVC addURL:[NSURL URLWithString:@"http://www.putclub.com"]];
    // 弹出分享控制器
    [self presentViewController:composeVC animated:YES completion:nil];
    // 监听用户点击事件
    composeVC.completionHandler = ^(SLComposeViewControllerResult result){
        if (result == SLComposeViewControllerResultDone) {
            NSLog(@"点击了发送");
        }
        else if (result == SLComposeViewControllerResultCancelled)
        {
            NSLog(@"点击了取消");
        }
    };
}else{
    NSLog(@"点击了取消");
}`

你可能感兴趣的:(分享facebook.分享instagram其他代码)