我工作的iOS应用,凡在我appDelegate
我:等待,直到异步API调用完成 - 斯威夫特/ IOS
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
self.api.signInWithToken(emailstring, token: authtokenstring) {
(object: AnyObject?, error:String?) in
if(object != nil){
self.user = object as? User
// go straight to the home view if auth succeeded
var rootViewController = self.window!.rootViewController as UINavigationController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var homeViewController = mainStoryboard.instantiateViewControllerWithIdentifier("HomeViewController") as HomeViewControllerenter
// code here
rootViewController.pushViewController(homeViewController, animated: true)
}
}
return true
}
的api.signInWithToken
是Alamofire由异步调用,我会喜欢在func应用程序的最后端返回true之前等待它完成。
Swift没有这种功能。您需要在'didFinishLaunching'主体中设置窗口和根视图控制器,可能需要使用加载图形,然后导航到API登录完成处理程序中的新视图控制器。 – 2014-11-06 20:10:12
didFinishLaunching已弃用,但听起来像个好主意 – 2014-11-07 21:51:45