国外第三方分享,包括Facebook,twitter,Instagram

1.facebook ,twitter等

通过iphone自带的分享,首先导入Social.framework,然后导入

#import <Social/Social.h>

最后通过以下代码完成分享:

SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:sharedName];

    BOOL success = [composeVc setInitialText:self.sharedContent];//分享内容

    BOOL imageSuccess = [composeVc addImage:self.sharedImage];//分享的图片

    //回调

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){

        if (result == SLComposeViewControllerResultCancelled) {

            NSLog(@"Cancelled");

        }else{

            NSLog(@"Post");

        }

        [composeVc dismissViewControllerAnimated:YES completion:Nil];

    };

    composeVc.completionHandler = myBlock;

    if(success && imageSuccess)

        [self presentViewController:composeVc animated:YES completion:nil];

}

2.Instagram稍微麻烦一点,通过 UIDocumentInteractionController完成分享,首先还是要先判断Instagram是否存在,如果存在再进行分享的操作。
代码如下:

- (void)instagramShare:(UIView*)view{

    UIImage* image = [UIImage imageNamed:@"csh.jpg"];//分享的图片

    CGFloat cropVal = (image.size.height > image.size.width ? image.size.width : image.size.height);  

    cropVal *= [image scale];    

    CGRect cropRect = (CGRect){.size.height = cropVal, .size.width = cropVal};

    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);    

    NSData *imageData = UIImageJPEGRepresentation([UIImage imageWithCGImage:imageRef], 1.0);

    CGImageRelease(imageRef);

    NSString *writePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"instagram.igo"];

    if (![imageData writeToFile:writePath atomically:YES]) {

        // failure

        NSLog(@"image save failed to path %@", writePath);

        return;

    } else {

        // success.

    }

    // send it to instagram.

    NSURL *fileURL = [NSURL fileURLWithPath:writePath];

    self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];

    self.documentController.delegate = self;

    [self.documentController setUTI:@"com.instagram.exclusivegram"];

    [self.documentController setAnnotation:@{@"InstagramCaption" : @"My love dyl"}];    

    CGRect rect = CGRectMake(0 ,0 , 0, 0);

    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIGraphicsEndImageContext();

    [self.documentController presentOpenInMenuFromRect:rect inView:view animated:YES];

}


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值