ios - MFMailComposeViewController 困惑

标签 ios objective-c mfmailcomposeviewcontroller

我最近学习了如何在 iOS 应用程序中实现电子邮件,但我对这意味着什么感到困惑。我已附上错误以及代码。我想做的是让用户在 UITextField 中输入信息,当他们按下发送时,它将发送到我的电子邮件。我在过去几次运行它时遇到了这些错误,但我仍然感到困惑。预先感谢您!

    Information:Information:Building target 'RPSS' from 'RPSS' with configuration 'Debug' for architecture 'i386' using 'Simulator - iOS 4.3' sdk
    Error:Error:The following build commands failed:
    Error:Error:RPSS:
    Error:Error:Ld "/Users/abowmanj/Documents/Xcode projects/RPSS/build/Debug-               iphonesimulator/RPSS.app/RPSS" normal i386
    Error:Error:Build Finished with Error: 1
    Undefined symbol '_OBJC_CLASS_$_MFMailComposeViewController' referenced from:
    Error:Error:objc-class-ref-to-MFMailComposeViewController in RPSSViewController.o
    Error:Error:objc-class-ref-to-MFMailComposeViewController in SupportPage.o
    build/Debug-iphonesimulator/RPSS.app/RPSS
    Information:Information:ld: symbol(s) not found
    Information:Information:collect2: ld returned 1 exit status

代码:

-(void) showEmailModalView {
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;// <- very important step if you want feedbacks on what the user did with your email sheet

    [picker setSubject:@"Comments, Suggestions, Etc."];

    // Fill out the email body text
    NSString *emailBody = [NSString stringWithFormat: @"%@", supportInput.text];

    [picker setMessageBody:emailBody isHTML:YES]; // depends. Mostly YES, unless you want to send it as plain text (boring)

    picker.navigationBar.barStyle = UIBarStyleDefault; // choose your style, unfortunately, Translucent colors behave quirky.

    [self presentModalViewController:picker animated:YES];
    [picker release];
 }

 - (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    if (result == MFMailComposeResultSent) {
        UIAlertView *sentMail = [[UIAlertView alloc] initWithTitle: @"Mail Sent:" message: @"Your mail has been sent!" delegate: self cancelButtonTitle: nil otherButtonTitles: @"Close", nil];
        [sentMail show];
        [sentMail release];
    }

    [self dismissModalViewControllerAnimated:YES];
}

-(IBAction) send : (id) sender {
    // We must always check whether the current device is configured for sending emails
    if ([MFMailComposeViewController canSendMail]) {
        [self showEmailModalView];
    }
    else {
        UIAlertView *a = [[UIAlertView alloc] initWithTitle: @"Error" message: @"Device not configured to send mail." delegate: self cancelButtonTitle: nil otherButtonTitles: @"Ok", nil];
        [a show];
        [a release];
     }
}

最佳答案

您需要包含 MessageUI 框架。看看How to "add existing frameworks" in Xcode 4?

关于ios - MFMailComposeViewController 困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269449/

相关文章:

ios - UiAlertView 和 UIProgressView 用于在本地复制文件

ios - 未调用 MFMailComposeViewControllerDelegate

iphone - NSString 形式的 HTML 电子邮件模板

ios - DeviceCheck API - iOS 设备的唯一标识符?

ios - Xcode 6 View 调试不可用

ios - 传递给另一个类时,NSString 的 id 返回 null

iphone - 归档项目时 Apple Mach-O 链接器错误

ios - QT如何改变应用程序窗口z索引

ios - MFMailComposeViewController 的自定义 UINavigationBar

ios - 如何在接收设备上用另一个推送通知替换一个推送通知?