Ứng dụng của tôi cho phép người dùng chụp ảnh và thêm lớp phủ trước khi lưu.Ảnh chia sẻ iOS trên Mạng xã hội
Tôi muốn cho phép người dùng chia sẻ ảnh của mình bằng bất kỳ ứng dụng nào có thể xử lý hình ảnh (ví dụ: email, facebook, twitter ...), như Intent trên Android.
Tôi đã cố gắng sử dụng UIDocumentController, nhưng nó không hiển thị Facebook hoặc Twitter như trong thư viện chính thức. Nó cũng làm cho ứng dụng của tôi bị treo sau khi chụp bức ảnh thứ hai.
Có cách nào đơn giản để làm như vậy không? Tôi không muốn sử dụng Facebook SDK và vân vân.
Đây là những gì tôi làm khi ảnh được chụp:
[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);
}
}];
Trông tuyệt vời, cảm ơn! Không có nút được tạo sẵn để người dùng chọn? – Oyashiro
nó hoạt động gần như hoàn hảo, nhưng khi tôi gửi một email nó gửi nó, nhưng bộ điều khiển không được loại bỏ bao giờ hết, có một số phương pháp để trở lại xem trước sau khi thành công? – suMi
Đã chỉnh sửa câu trả lời. Điểm kiểm tra số 5. – vforvendetta