我的应用程序中有电话提示警报对话框。我正在 iOS 10.1.1 和 iPhone 7 设备上运行。在显示对话框之前,我需要显示一个隐藏在 View Controller 中的 View ,但在 iPhone 7 中它不会显示,直到我对提词提示采取任何操作。下面是在其他 iOS 上运行良好的代码。您的帮助将不胜感激。
[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]];
});
您还应注意,自 iOS 10 起,UIApplication openURL:
方法已弃用。它已被替换为 openURL:options:completionHandler:
。在 iOS 10 下,使用这种新方法可能是解决您问题的另一种方法。参见 https://stackoverflow.com/a/39767062/1226963了解如何根据设备的当前 iOS 版本使用两个版本的 openURL:
。
关于ios - 在 iOS 中显示 View 之前显示提示警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40509970/