我在我的应用程序的注册过程中使用Twitter登录。我要求用户的电子邮件。一旦我得到它,我想提出一个UIAlertController。Swift尝试呈现其视图不在窗口层次结构中的UIAlertController(在TWTRShareEmailViewController之后呈现)
这里是我的代码:
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没有被驳回):
警告:试图提出UIALertController上xViewController其 看法是不在窗口层次结构中!
任何想法,我应该写这个?我如何知道TWTRShareEmailViewController
何时被解雇以继续注册过程并能够呈现我的UIAlertController
?我不知道与TWTRShareEmailViewController
相关的代理方法。
任何帮助表示赞赏。谢谢。
您是否找到针对此问题的更好解决方案?我也在使用dispatch_async – 2016-03-04 15:50:46
正如我在编辑回复中解释的那样,我有一个专门针对Twitter的东西。因此,当用户想用Twitter登录时,我模式地展示了我的'TWLoginVC',其中的一切都完成了(在某些情况下避免了奇怪的行为,例如VC之间的特殊转换)。但是我改了一下我的代码,我不需要再提供一个UIAlertController。所以没有抱歉,我没有更好的解决方案:/ – 2016-03-04 17:43:58
随着新的TwitterKit(我刚刚更新到2.0版。2),要求更改用户电子邮件的方式。它在Twitter文档中解释:https://docs.fabric.io/ios/twitter/request-user-email-address.html。 – 2016-04-22 12:56:26