3
用戶拍攝照片後,我成功地將圖像保存到我的應用程序。我想要做的事情是,當用戶回到應用程序時,我希望他們能夠以附件的形式通過電子郵件發送照片。我沒有任何運氣將應用程序中的數據轉換爲圖像,所以我可以添加爲附件。請有人指點我正確的方向。這是拍攝照片後保存圖像的位置。從應用程序和電子郵件檢索已保存的圖像
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//here is the image returned
app.aImage2 = [info objectForKey:UIImagePickerControllerOriginalImage];
NSData *imageData = UIImagePNGRepresentation(app.aImage2);
NSString * savedImageName = [NSString stringWithFormat:@"r%@aImage2.png",app.reportNumber];
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * dataFilePath;
dataFilePath = [documentsDirectory stringByAppendingPathComponent:savedImageName];
[imageData writeToFile:dataFilePath atomically:YES];
[self dismissModalViewControllerAnimated:YES];
}
這裏是我需要附加它的地方。
//this is inside my method that creates an email composer view
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
//how would i attach the saved image from above?
有不有機會測試這些代碼,但這應該引導你在ri裏面ght方向。不太確定你的「app.aImage2」是什麼(我假設它是一個UIImage,你已經聲明在某處)。 – fuzz 2011-05-17 06:11:41
對不起忘了添加「app.aImage2」是我的應用程序委託中的全局UIImage。這工作!我不得不編輯一點,但謝謝! – Louie 2011-05-17 15:57:21
大部分代碼似乎都是基於Mike在這裏提供的:http://stackoverflow.com/questions/1527351/how-to-add-an-uiimage-in-mailcomposer-sheet-of-mfmailcomposeviewcontroller-in- iph/2461451#2461451,所以最好給出適當的引用。 – 2011-05-27 16:27:25