Vikings
Vikings

Reputation: 2527

iPhone In App Mail Compile Warning

My in app email is now working, but i'm getting a compile warning. I would like to fix this, any help or suggestions would be appreciated.

I'm getting this warning.

/Users/vikings1201/Documents/iPhone Applications/LittleTipper_4.0/tipApp/Classes/tipAppViewController.m:1083:0 /Users/vikings1201/Documents/iPhone Applications/LittleTipper_4.0/tipApp/Classes/tipAppViewController.m:1083: warning: class 'tipAppViewController' does not implement the 'MFMailComposeViewControllerDelegate' protocol

-(IBAction)sendMail {

    MFMailComposeViewController *mailComposer = [[[MFMailComposeViewController alloc] init] autorelease] ;
    mailComposer.mailComposeDelegate = self;

    if ([MFMailComposeViewController canSendMail]) {
        [mailComposer setToRecipients:nil];
        [mailComposer setSubject:nil];
        [mailComposer setMessageBody:@"Default text" isHTML:NO];

        [self presentModalViewController:mailComposer animated:YES];
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller  
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError*)error {

    [controller dismissModalViewControllerAnimated:YES];
}

Upvotes: 0

Views: 177

Answers (3)

Tom Belote
Tom Belote

Reputation: 590

Should be pretty simple. You need to add as an interface that is implemented by tipAppViewController in the tipAppViewController.h file. Something like this.

@interface tipAppViewController : UIViewController<MFMailComposeViewControllerDelegate> {

You already are implementing – mailComposeController:didFinishWithResult:error: it just needs to be in your header file.

Upvotes: 0

Jim
Jim

Reputation: 73966

MFMailComposeViewController expects to be able to send certain messages to its delegate. The messages are defined as a protocol. You are setting the delegate to an instance of your tipAppViewController class, but that class doesn't implement this protocol. You need to a) implement the required methods, and b) define the class as implementing that protocol.

See: Learning Objective-C: A Primer

Upvotes: 0

Dan Ray
Dan Ray

Reputation: 21903

It's trying to protect you from setting the .delegate property to an object that might not implement the delegate methods.

In your .h file, you need to make it declare that it implements the delegate protocol.

@interface myVC : UIViewController <MFMailComposeViewControllerDelegate>
{
...
}

Upvotes: 1

Related Questions