I have this code that runs a 15 second delay timer before it sends an SMS:
timer = [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(sendMessage) userInfo:nil repeats:NO];
This code goes to a method called waitScreen that displays a view controller with an activity indicator and a label telling the user that the 15 second timer is in place. After the 15 second timer, this view is dismissed (please see code below) and then I want to launch the MFMessageComposeViewController
view with the user's body and recipient already in place. Due to iOS inability to automatically send SMS, the user have to tap Send for the SMS message to be sent.
This is my sendMessage method:
- (void)sendMessage {
[self dismissModalViewControllerAnimated:YES];
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText]){
controller.body = messageField.text;
controller.recipients = [NSArray arrayWithObjects:contactNumber.text,nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
The messageField
is a UITextField
where a user types the SMS message while the contactNumber is the contact's number from the address book.
My question is why is my MFMessageComposeViewController
not launching? Is there a better way to do it? Thanks!
Does it work if you change your first line to