iOS在社交网络上共享图片
我的应用程序允许用户拍照,并在保存前添加覆盖 我想让用户使用任何能够处理图像的应用程序(例如:电子邮件、facebook、twitter……)来分享他的照片,比如安卓系统 我试着使用UIDocumentController,但它不像在官方画廊中那样显示Facebook或Twitter。这也使得我的应用程序在拍摄第二张照片后崩溃 有没有一个简单的方法可以做到这一点?我不想使用Facebook SDK等等 以下是我在拍照时所做的:iOS在社交网络上共享图片,ios,image,sharing,Ios,Image,Sharing,我的应用程序允许用户拍照,并在保存前添加覆盖 我想让用户使用任何能够处理图像的应用程序(例如:电子邮件、facebook、twitter……)来分享他的照片,比如安卓系统 我试着使用UIDocumentController,但它不像在官方画廊中那样显示Facebook或Twitter。这也使得我的应用程序在拍摄第二张照片后崩溃 有没有一个简单的方法可以做到这一点?我不想使用Facebook SDK等等 以下是我在拍照时所做的: [stillImageOutput captureStillImag
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:
^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
if(!error){
//Resize the picture and add the overlay
UIImage *picture = [self imageFromSampleBuffer:imageSampleBuffer];
//Custom code letting me save the picture in a specific album
[self.library saveImage:picture toAlbum:@"myApp" metadata:metadata withCompletionBlock:^(NSError *error,NSURL* assetURL) {
if (error!=nil) {
NSLog(@"Big error: %@", [error description]);
} else {
NSLog(@"Image Saved");
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"tmp.jpg"];
//Only way to use UIDocumentController is to save the file at a known location
NSData* imagedata = UIImageJPEGRepresentation(picture, 0.9f);
[imagedata writeToFile:path atomically:NO];
NSLog(@"%@",path);
docController.URL = [NSURL fileURLWithPath:path];
// This make my app crash after the second picture
[docController presentPreviewAnimated:YES];
}
}];
} else {
NSLog(@"%@",error);
}
}];
iOS内置了一个社交共享工具包。您可以通过电子邮件、Facebook和Twitter共享图像。但要使用Google+和其他社交服务,您需要它们各自的SDK 1) 对于Facebook
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:message];
[controller addImage:image];
[self presentViewController:controller animated:YES completion:Nil];
2) 对于twitter,将SLServiceTypeFacebook替换为SLServiceTypeTwitter
3) 电子邮件
MFMailComposeViewController *emailShareController = [[MFMailComposeViewController alloc] init];
emailShareController.mailComposeDelegate = self;
[emailShareController setSubject:@"Share Image"];
[emailShareController setMessageBody:message isHTML:NO];
[emailShareController addAttachmentData:UIImageJPEGRepresentation(image, 1) mimeType:@"image/jpeg" fileName:@"your_image.jpeg"];
if (emailShareController) [self presentViewController:emailShareController animated:YES completion:nil];
4) 请记住将Social.Framework添加到项目和以下头文件中
#import <MessageUI/MFMailComposeViewController.h>
#import <Social/Social.h>
#import <MobileCoreServices/MobileCoreServices.h>
看起来很棒,谢谢!没有预先构建的按钮让用户选择?它工作得几乎完美,但当我发送电子邮件时,它会发送,但控制器从未被解除,是否有一些方法可以在成功后返回到以前的视图?
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}