Question

I am trying to get a basic sample of in-app email working, and getting a linker error which seems to relate to the MessageUI framework. IN my .h file I have

 #import <UIKit/UIKit.h>
 #import <MessageUI/MessageUI.h>

 @interface ButtonViewController : UIViewController
 <MFMailComposeViewControllerDelegate>
 {
        MFMailComposeViewController *mailComposer;
 }

and in my .m file I use that mailComposer object. I alloc init it and set it, without compiler errors.

 mailComposer =[[MFMailComposeViewController alloc] init];
 mailComposer.mailComposeDelegate = self;
 [mailComposer setSubject:@"Test mail"];
 [mailComposer setMessageBody:@"Testing Message Body" isHTML:NO];

 [self presentViewController:mailComposer animated:YES completion:nil];

But I do get linker errors. I think I'm missing something I need to do up front.

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MFMailComposeViewController", referenced from:
  objc-class-ref in ButtonViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(null): "_OBJC_CLASS_$_MFMailComposeViewController", referenced from:

(null): Objc-class-ref in ButtonViewController.o

(null): Symbol(s) not found for architecture i386

(null): Linker command failed with exit code 1 (use -v to see invocation)

Thank you. Laurel

Was it helpful?

Solution

You need to link MessageUI framework.
Go to your project settings, select correct target -> general, scroll down to "linked frameworks and libraries" press + and add MessageUI.framework

OTHER TIPS

What you might have done is you added the MessageUI.framework and moved it to some other folder within the bundle thus not updating the path for xcode. Xcode thinks that the file is missing as it appears red in project->targets->link binary with libraries in the image given below. Adding the MessageUI.framework to the project might solve the problem

See the red missing framework or it might not be there totally so add it again

I've encountered Linker Error generally when I create duplicate classes. (Generally while using core data). SO , Just go to "Build Phases" -> "Compile Sources" and look for duplicate of classes(Classes being used with ButtonViewController).

If it does not solve your issue, as you have imported messageUI, #import <MessageUI/MessageUI.h>

Check if messageUI framework is added in project. if not, add it in project. Clean the project & you are good to go then

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top