i’m having troubles with my MFMessageComposeViewController. I would like to use SMS in-app.
Everything work fine for sending SMS, so far so good. But when i hit the cancel button (or send button too) top of my view disapeared but the keyboard did not. It’s maybe because i don’t use modale view, but only a addSubview.
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled)
{
NSLog(@"Message annulé");
[controller resignFirstResponder];
[controller.view removeFromSuperview];
[controller release];
}
else if (result == MessageComposeResultSent)
{
NSLog(@"Message envoyé");
...
}
else
{
NSLog(@"Message non envoyé");
...
}
}
-(void)sendSMS:(NSString *)bodyOfMessage :(Phone *)recipient
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSMutableArray *toRecipients = [[NSMutableArray alloc]init];
[toRecipients addObject:recipients.phoneNumber];
[picker setRecipients:(NSArray *)toRecipients];
[toRecipients release];
NSString *bodyString = nil;
bodyString = bodyOfMessage;
[picker setBody:bodyString];
[self addSubView:picker.view];
[picker release];
}
}
Any idea ? Had I to use only modalView ?
sorry for spelling mistake…
Thank you. Tommy
Yes, you have to use the modalviewcontroller.
Also, you’re creating two instances of the MFMessageComposeViewController, first for checking if it can send text and then another to actually show it. I advise to create just one, it’s better for the memory 🙂 also the first one is leaking since you didn’t release it. Good luck!