我工作的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