您的位置:首页 > 其它

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

2016-01-07 19:24 351 查看
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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: