2014-01-08 3 views
-1

안녕하세요 저는 완전히 단서가 없습니다. 버튼을 클릭하면 "이메일"을 보내고 이메일에 pdf 첨부 파일을 보내려고합니다. 내가처음부터 pdf 첨부 파일이있는 이메일을 만들 수있는 방법

- (id)initWithStyle:(UITableViewStyle)style 
{ 
self = [super initWithStyle:style]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

_files = @[@"Elementry application 2015.pdf",@"HS application 2015.pdf"]; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
// Return the number of sections. 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
// Return the number of rows in the section. 
return [_files count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
AttachmentTableViewCell *cell = (AttachmentTableViewCell*)[tableView  dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

// Configure the cell... 
cell.fileLabel.text = [_files objectAtIndex:indexPath.row]; 
cell.thumbnail.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon%d.png", indexPath.row]]; 

return cell; 
} 


#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *selectedFile = [_files objectAtIndex:indexPath.row]; 
[self showEmail:selectedFile]; 
} 


- (void)showEmail:(NSString*)file { 

NSString *emailTitle = @"Registration Forms Ateres App"; 
NSString *messageBody = @"Send forms to your email so you can print it out and fill out the  form!!"; 
NSArray *toRecipents = [NSArray arrayWithObject:@""]; 

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
mc.mailComposeDelegate = self; 
[mc setSubject:emailTitle]; 
[mc setMessageBody:messageBody isHTML:NO]; 
[mc setToRecipients:toRecipents]; 

// Determine the file name and extension 
NSArray *filepart = [file componentsSeparatedByString:@"."]; 
NSString *filename = [filepart objectAtIndex:0]; 
NSString *extension = [filepart objectAtIndex:1]; 

// Get the resource path and read the file using NSData 
NSString *filePath = [[NSBundle mainBundle] pathForResource:filename ofType:extension]; 
NSData *fileData = [NSData dataWithContentsOfFile:filePath]; 

// Determine the MIME type 
NSString *mimeType; 
if ([extension isEqualToString:@"jpg"]) { 
    mimeType = @"image/jpeg"; 
} else if ([extension isEqualToString:@"png"]) { 
    mimeType = @"image/png"; 
} else if ([extension isEqualToString:@"doc"]) { 
    mimeType = @"application/msword"; 
} else if ([extension isEqualToString:@"ppt"]) { 
    mimeType = @"application/vnd.ms-powerpoint"; 
} else if ([extension isEqualToString:@"html"]) { 
    mimeType = @"text/html"; 
} else if ([extension isEqualToString:@"pdf"]) { 
    mimeType = @"application/pdf"; 
} 

// Add attachment 
[mc addAttachmentData:fileData mimeType:mimeType fileName:filename]; 

// Present mail view controller on screen 
[self presentViewController:mc animated:YES completion:NULL]; 

} 

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError *)error 
{ 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     NSLog(@"Mail cancelled"); 
     break; 
    case MFMailComposeResultSaved: 
     NSLog(@"Mail saved"); 
     break; 
    case MFMailComposeResultSent: 
     NSLog(@"Mail sent"); 
     break; 
    case MFMailComposeResultFailed: 
     NSLog(@"Mail sent failure: %@", [error localizedDescription]); 
     break; 
    default: 
     break; 
} 

// Close the Mail Interface 
[self dismissViewControllerAnimated:YES completion:NULL]; 
} 

@end 
//but it wants a AttachmentTableViewCell.h and .m but for some reason i don't know how i can attach that with main story board, like attach the label and make an ib outlet on the cell like this @interface AttachmentTableViewCell : UITableViewCell 
@property (weak, nonatomic) IBOutlet UIImageView *thumbnail; 
@property (weak, nonatomic) IBOutlet UILabel *fileLabel; 

    @end 

사람이 내가 그것을 테이블 형태로 원하고 당신이 그것을 클릭 할 때 이미이에 첨부 된 PDF 파일과 함께 이메일로 바로 이동합니다 나에게 도와주십시오 @implementation의 AttachmentTableViewController을하고 시도 것은 어디 코드 캠 efrom하지만 내가 만들고있어 그래서 만약 누군가가 대답을하시기 바랍니다 어떻게 알고 응용 프로그램에서 추가하고 싶습니다! http://www.appcoda.com/ios-programming-create-email-attachment/

+0

게시 한 모든 코드에 어떤 문제가 있는지 언급하지 않았습니다. 모든 사람들이 코드를 전부 읽지 않도록하십시오. 사람들이 쉽게 도울 수 있도록하십시오. 문제에 대한 세부 정보를 제공하십시오. – rmaddy

답변

0

우리는 우리가 우리의 행동 방식에 다음과 같은 쓰기 버튼을 만들고 그게 뭔지에 액션을 첨부 :

- (IBAction)generatePdfButtonPressed:(id)sender 
{ 
    pageSize = CGSizeMake(612, 792); 
    NSString *fileName = @"Demo.pdf"; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName]; 

    [self generatePdfWithFilePath:pdfFileName]; 

}

참조 Click

가 유용 희망 자세한 내용은 :)

관련 문제