国外第三方分享,包括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];
}
通过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];
}
相关文章推荐
- JavaScript中DOM的层次节点(二)
- 上传jar包到nexus私服
- Java基础恶补——内存泄露、内存溢出
- Swift开发--多个UIViewController之间传值
- 格言
- extjs createDelegate的作用
- 关于JDK编译版本详解
- Android Studio常用快捷键
- 纯js ajax请求
- UIWebView 加载数据的方式
- UI课程(图片动画/视图控制器/自定义视图/循环导入)
- Spring(AbstractRoutingDataSource)实现动态数据源切换
- 2016-1-7-Thingking in Java 读书笔记(四)---控制执行流程
- itext
- 购物车设计思路
- Java:单例模式的七种写法
- new的实现原理
- 简单的html渲染模板引擎
- uva10622 Perfect P-th Powers
- pip: 修改源地址