Oya*_*iro 10 image sharing ios
我的应用程序让用户拍照,并在保存前添加叠加层.
我想让用户使用任何能够处理图像的应用程序(例如:电子邮件,脸书,推特...)分享他的照片,就像Android上的Intent一样.
我试图使用UIDocumentController,但它没有像在官方图库中那样显示Facebook或Twitter.它还使我的应用程序在拍摄第二张照片后崩溃.
有一个简单的方法吗?我不想使用Facebook SDK等.
这是我拍摄照片时的所作所为:
[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);
}
}];
Run Code Online (Sandbox Code Playgroud)
vfo*_*tta 13
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];
Run Code Online (Sandbox Code Playgroud)
2)对于twitter,用SLServiceTypeTwitter替换SLServiceTypeFacebook.
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];
Run Code Online (Sandbox Code Playgroud)
4)记得将Social.Framework添加到项目和以下头文件中
#import <MessageUI/MFMailComposeViewController.h>
#import <Social/Social.h>
#import <MobileCoreServices/MobileCoreServices.h>
Run Code Online (Sandbox Code Playgroud)
5)将视图控制器设置为委托
MFMailComposeViewControllerDelegate
发送邮件后,解除MailViewController-
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5881 次 |
| 最近记录: |