iPhone App里添加能发送附件的Email功能

来源:互联网 发布:linux怎么退出root用户 编辑:程序博客网 时间:2024/04/29 19:41
想在iPhone App里添加能发送附件的Email功能。可以加入messageUI.framework

添加附件代码
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
            NSString *pathHome = [path objectAtIndex:0];
            NSString *filePath = [pathHome stringByAppendingPathComponent:@"info.txt"];
            if( [MFMailComposeViewController canSendMail] )
            {
                MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
                picker.mailComposeDelegate = self;
                
                [picker setSubject:@" "];
                
                
                NSLog(@"filePath = %@",filePath);
     
                NSData* data = [NSData dataWithContentsOfFile:filePath];
                [picker addAttachmentData:data mimeType:@"txt" fileName:@"info.txt"];
                
                NSString *emailBody = @" ";
                [picker setMessageBody:emailBody isHTML:YES];
                
                [self presentModalViewController:picker animated:YES];
                [picker release];
            }
原创粉丝点击