Reputation: 793
i'm having a problem with my MFMessageComposeController. So, in my app every time you click on a button, a UIActionSheet appears and then you have to select if you want to make a call or send a message . But every time that i make a call, end it and return to my app, my MFMessageComposeController appears... where could the problem be ? here is the code if it helps
case 0 : {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
[actionSheet dismissWithClickedButtonIndex:0 animated:NO];
}
case 1: {
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}
[[UIApplication sharedApplication ] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
MFMessageComposeViewController*controller =[[[MFMessageComposeViewController alloc] init] autorelease];
if ([MFMessageComposeViewController canSendText]) {
controller.body = [NSString stringWithFormat:@"Narucio bih Oryx Taxi na lokaciju ( %@ , %@ ) .\nNaruci! aplikacija", latitudePoint.text, longitudePoint.text];
controller.recipients = [NSArray arrayWithObjects:@"011888",nil];
//controller.messageComposeDelegate = self;
controller.messageComposeDelegate=self;
controller.navigationBar.tintColor = [UIColor grayColor];
[self presentModalViewController:controller animated:YES];
Upvotes: 0
Views: 489
Reputation: 19469
You need to put break;
after each case is completed, just to make sure that execution of the cases following the current case don't take place.
Try this code:
case 0 : {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
[actionSheet dismissWithClickedButtonIndex:0 animated:NO];
break;
}
case 1: {
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
break;
}
default:
break;
MFMessageComposeViewController*controller =[[[MFMessageComposeViewController alloc] init] autorelease];
if ([MFMessageComposeViewController canSendText]) {
controller.body = [NSString stringWithFormat:@"Narucio bih Oryx Taxi na lokaciju ( %@ , %@ ) .\nNaruci! aplikacija", latitudePoint.text, longitudePoint.text];
controller.recipients = [NSArray arrayWithObjects:@"011888",nil];
//controller.messageComposeDelegate = self;
controller.messageComposeDelegate=self;
controller.navigationBar.tintColor = [UIColor grayColor];
[self presentModalViewController:controller animated:YES];
}
Hope this helps you.
Upvotes: 0
Reputation: 7644
You haven't ended the switch statement's case 0
so even if it executes the first case, it always goes into the second case too. The solution is using break
:
case 0 : {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
[actionSheet dismissWithClickedButtonIndex:0 animated:NO];
break;
}
case 1: {
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
break;
}
Upvotes: 0
Reputation: 15722
You need to add a break after each case in your switch statement. Otherwise execution will fall through to the next case.
case 0 : {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"tel://011212"]];
[actionSheet dismissWithClickedButtonIndex:0 animated:NO];
break;
}
case 1: {
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
break;
}
Upvotes: 1