MessageComposeResult UIAlert 未显示
MessageComposeResult UIAlert Not showing
我正在尝试获取一个 UIAlert,它会在用户发送短信时显示 "message sent"。这是我的。
- (void)messageComposeViewController:(MFMessageComposeViewController
*)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled)
{
}
else if (result == MessageComposeResultSent)
{
UIAlertController* messageSent = [UIAlertController alertControllerWithTitle:@"" message:@"Message Sent." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault
handler:NULL];
[messageSent addAction:okAction];
[self.presentViewController:messageSent animated:YES completion:nil];
}
else
NSLog(@"Message failed");
[self dismissViewControllerAnimated:YES completion:NULL];
}
当我 运行 应用程序发送消息时,没有出现 UIAlert。 Xcode 还说,
警告:试图展示其视图不在 window 层次结构中!
我哪里错了?
我没有使用过 MFMessageComposeViewController,但我认为您必须先关闭 MFMessageComposeViewController,然后在完成时显示警报,如下所示。尝试一下,让我知道是否可行,也许自己指的是 MFMessageComposeViewController?不确定!
else if (result == MessageComposeResultSent)
{
[controller dismissViewControllerAnimated:true completion:^{
UIAlertController* messageSent = [UIAlertController alertControllerWithTitle:@"" message:@"Message Sent." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault
handler:NULL];
[messageSent addAction:okAction];
[self presentViewController:messageSent animated:true completion:^{
//try anything on completion
}];
}];
}
我正在尝试获取一个 UIAlert,它会在用户发送短信时显示 "message sent"。这是我的。
- (void)messageComposeViewController:(MFMessageComposeViewController
*)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled)
{
}
else if (result == MessageComposeResultSent)
{
UIAlertController* messageSent = [UIAlertController alertControllerWithTitle:@"" message:@"Message Sent." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault
handler:NULL];
[messageSent addAction:okAction];
[self.presentViewController:messageSent animated:YES completion:nil];
}
else
NSLog(@"Message failed");
[self dismissViewControllerAnimated:YES completion:NULL];
}
当我 运行 应用程序发送消息时,没有出现 UIAlert。 Xcode 还说, 警告:试图展示其视图不在 window 层次结构中! 我哪里错了?
我没有使用过 MFMessageComposeViewController,但我认为您必须先关闭 MFMessageComposeViewController,然后在完成时显示警报,如下所示。尝试一下,让我知道是否可行,也许自己指的是 MFMessageComposeViewController?不确定!
else if (result == MessageComposeResultSent)
{
[controller dismissViewControllerAnimated:true completion:^{
UIAlertController* messageSent = [UIAlertController alertControllerWithTitle:@"" message:@"Message Sent." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"style:UIAlertActionStyleDefault
handler:NULL];
[messageSent addAction:okAction];
[self presentViewController:messageSent animated:true completion:^{
//try anything on completion
}];
}];
}