我的应用程序允许用户拍照并在保存之前添加覆盖层。
我想让用户使用能够处理图像的任何应用程序(例如:电子邮件、Facebook、Twitter等)分享他的图片,就像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);
}
}];