在iOS中显示视图之前的Teleprompt警报对话框显示

问题描述:

我的应用程序中有telprompt警报对话框。我在iOS 10.1.1和iPhone 7设备上运行。在显示对话框之前,我需要显示一个在视图控制器中隐藏的视图,但在iPhone 7中它不会显示,直到我对teleprompt采取任何操作。下面是在其他iOS上正常工作的代码。您的帮助将不胜感激。在iOS中显示视图之前的Teleprompt警报对话框显示

[callView setHidden:NO]; 
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:msg]; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 

它与iPhone 7无关。它与iOS版本有关。

一个简单的解决方案是将呼叫延迟到openURL:,让您的代码有机会完成隐藏callView

[callView setHidden:NO]; 
dispatch_async(dispatch_get_main_queue(), ^{ 
    NSString *phoneNumber = [@"telprompt://" stringByAppendingString:msg]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]; 
}); 

你也应该注意到,UIApplication openURL:方法已为iOS的10已替换为openURL:options:completionHandler:。在iOS 10下,使用这种新方法可能是解决您的问题的另一种方法。请参阅https://stackoverflow.com/a/39767062/1226963了解如何使用两个版本的openURL:,具体取决于设备的当前iOS版本。

+0

谢谢我的问题是通过给定的堆栈溢出链接来解决的。 –