我正在开发一个iOS应用程序,在我的appDelegate
中有以下内容:
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之前,我希望等待其完成。
didFinishLaunching
的主体中设置窗口和根视图控制器,可能还要加上一个加载图形,然后在API登录完成处理程序中导航到新的视图控制器。 - Nate Cook