I want to send sms using below code in iPhone 4, but the application is crashing due to this code only.
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *smsComposerController = [[[MFMessageComposeViewController alloc] init] autorelease];
[smsComposerController setBody:@"First SMS"];
smsComposerController.recipients = [NSArray arrayWithObjects:@"9886333333",@"9980444444",nil];
smsComposerController.messageComposeDelegate = self;
[smsComposerController release];
}
I am new for SMS sending , so can any one help me what I am doing wrong?
You need to add [self presentModalViewController:smsComposerController animated:YES];
ReplyDeletein your code to send the sms.
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *smsComposerController = [[[MFMessageComposeViewController alloc] init] autorelease];
[smsComposerController setBody:@"First SMS"];
smsComposerController.recipients = [NSArray arrayWithObjects:@"9886333333",@"9980444444",nil];
smsComposerController.messageComposeDelegate = self;
[self presentModalViewController:smsComposerController animated:YES];
}
You're autoreleasing and then releasing again smsComposerController.
ReplyDeleteJust release it once. You can review you memory management rules here.
if ([MFMessageComposeViewController canSendText]) {
ReplyDeleteMFMessageComposeViewController *smsComposerController = [[[MFMessageComposeViewController alloc] init] autorelease];
[smsComposerController setBody:@"First SMS"];
smsComposerController.recipients = [NSArray arrayWithObjects:@"9886333333",@"9980444444",nil];
smsComposerController.messageComposeDelegate = self;
[smsComposerController release]; <-------------- THIS IS YOUR ERROR
}
You should not release an auto-release object.