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?
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.