我在我的應用程序的註冊過程中使用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