使用 UIApplication.shared.open 连续调用多个 URL - 只先打开

Calling multiple URLs in succession using UIApplication.shared.open - only opens first

我正在尝试通过在 Xcode/Swift 中为 iPad 连续打开多个 URL 来创建 wifi tress 测试。它似乎只打开了第一个成功。 "sleep(x)" 调用没有区别。代码片段:

func counter()
{
    seconds -= 1
    label.text = String(seconds) + " Seconds"

    if (seconds == 0)
    {

        let url1 = URL(string: "http://www.wix.com")!
        let url2 = URL(string: "http://www.activistpost.com")!
        let url3 = URL(string: "http://www.time.com")!
        let url4 = URL(string: "http://www.steemit.com")!
        let url5 = URL(string: "http://www.youtube.com")!
        let url6 = URL(string: "http://www.cptts.net/61m.jpg")!

        if #available(iOS 10.0, *) {
            UIApplication.shared.open (url1)
            sleep (5)
            UIApplication.shared.open (url2)
            sleep (5)
            UIApplication.shared.open (url3)
            sleep (5)
            UIApplication.shared.open (url4)
            sleep (5)
            UIApplication.shared.open (url5)
            sleep (5)
            UIApplication.shared.open (url6)

        } else {
           // Fallback on earlier versions
        }

Xcode 10.0 测试版 2

正如我从 Apple documentation 引述的那样,它似乎只会执行第一个,应用程序将退出,如果找到它会启动另一个应用程序。

The URL you pass to this method can identify a resource in the app that calls the method, or a resource to be handled by another app. If the resource is to be handled another app, invoking this method might cause the calling app to quit so the other can launch.

所以最终你的应用程序退出然后你的其他调用将不会被执行。

I'm trying to create a wifi tress test

好吧,那不是怎么做的。另外,我想知道你是否真的需要这样做;开发人员工具已经允许您模拟繁忙的网络以进行测试。