xCode - Send SMS In-App

575 Views Asked by At

I wanna send a SMS from my App. I use for that following code:

.h

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

    @interface askFriendsViewController : UIViewController <MFMailComposeViewControllerDelegate>

-(IBAction)sms:(id)sender;

.m

-(IBAction)sms:(id)sender{

    MFMessageComposeViewController *textComposer = [[MFMessageComposeViewController alloc]init];
    [textComposer setMessageComposeDelegate:self];

    if ([MFMessageComposeViewController canSendText]) {
        [textComposer setBody:@"Text"];
        [self presentViewController:textComposer animated:YES completion:nil];
        [[UIApplication sharedApplication] setStatusBarHidden:YES];


        [textComposer preferredInterfaceOrientationForPresentation];
    }
    else {
        NSLog(@"SMS not working.");
    }


}

For the third line in the .m file I am getting an error:

Sending 'askFriendsViewController *const __strong' to parameter of incompatible type 'id'

What am I doing wrong?

1

There are 1 best solutions below

0
On

You declared your class to conform to the MFMailComposeViewControllerDelegate protocol instead of MFMessageComposeViewControllerDelegate in your header file. Change that to MFMessageComposeViewControllerDelegate and implements its messageComposeViewController:didFinishWithResult: method.