我在我的应用注册流程中使用 Twitter 登录,并要求用户提供电子邮件。一旦获取到电子邮件,我希望显示一个 UIAlertController。
这是我的代码:
func askForTWMail(){
if (Twitter.sharedInstance().session() != nil) {
let shareMailVC=TWTRShareEmailViewController(completion: {(mail:String!, error:NSError!) in
if (mail != nil) {
print("GOT MAIL: \(mail)")
self.gotMail()
}else{
print("MAIL VC ERROR: \(error)")
}
})
println("PRESENT MAIL VC")
self.presentViewController(shareMailVC, animated: true, completion: nil)
}else{
println("User not logged in")
}
}
func gotMail(){
var alertController=UIAlertController(title: "Some title", message: "Some message", preferredStyle: UIAlertControllerStyle.Alert)
var okAction=UIAlertAction(title:"Yes", style: UIAlertActionStyle.Default) {
UIAlertAction in
//some action
}
var cancelAction=UIAlertAction(title:"No", style: UIAlertActionStyle.Cancel){
UIAlertAction in
//some action
}
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
但是我遇到了这个错误(我想是因为TWTRShareEmailViewController没有被取消):
警告:试图在不在窗口层级结构中的xViewController上呈现UIALertController!
你有什么建议吗?我该如何知道TWTRShareEmailViewController
何时取消以继续注册过程并能够展示我的UIAlertController
?我不知道与TWTRShareEmailViewController
相关的委托方法。
任何帮助都将不胜感激。谢谢。