如何等待加载视图,直到应用从深层链接重新打开

时间:2019-04-29 13:25:11

标签: swift uiview grand-central-dispatch semaphore

因此,这是我要实现的目标: 我的应用程序中有一个登录屏幕。如果用户已登录,则应该立即对另一个视图执行搜索。如果不是,则应该执行登录请求并成功登录-对另一个视图执行segue。

问题是-我正在以松弛状态实施登录,因此流程如下:我正在使用

打开浏览器
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:483)
        at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
        at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:655)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
        at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:123)
        at io.restassured.specification.ResponseSpecification$statusCode$0.callCurrent(Unknown Source)
        at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:131)
        at io.restassured.internal.ValidatableResponseOptionsImpl.statusCode(ValidatableResponseOptionsImpl.java:119)

用户登录,然后通过深层链接重新打开应用程序。通过深层链接打开应用程序时,我将保存与后端服务器进行进一步通信所需的身份验证令牌。因此,我必须等到另一个控制器执行segue才能成功登录(另一个控制器需要来自后端服务器的数据)。

我现在尝试的是使用信号灯。

因此,我在登录视图viewDidLoad函数中有以下代码:

UIApplication.shared.open(url, options: [:], completionHandler: nil)

,并在AppDelegate中:

DispatchQueue.main.async {
    semaphore.wait()
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
    (...)
    Provider.semaphore.wait()
    self.performSegue(withIdentifier: "segueShowTabBar", sender: self)

    Provider.semaphore.signal()
}

Provider是我们用于API通讯的单例,因此它绝对是相同的信号量。

但是应用程序委托代码甚至没有运行,因为从深度链接打开应用程序时,其主线程仍停留在登录视图中的第二个Provider.semaphore.wait()上。

我要彻底解决这个问题吗?有没有办法等待执行此Segue并仍然能够从AppDelegate运行代码?

0 个答案:

没有答案