針對相機元件(UIImagePickerController)結束(dismiss)後,無法顯示錯誤訊息(UIAlertController)的處理。
我的解法是,在關閉 picker 的時候,在 完成時再去做 pop alert.
picker.dismiss(animated: true, completion: { self.present(alertController, animated: true, completion: { }) })
其他解法:
Found a solution here. I’m probably doing it wrong but if not it might be an Apple bug. The workaround is to delay the presentation of the UIAlertController
:
dispatch_async(dispatch_get_main_queue(), ^{
self.presentViewController(alertController, animated: true, completion: nil)
})
EDIT: I found another workaround (I don’t use the solution I put down here anymore). I had to change this because the Twitter login was also breaking my transitions between VCs.
I now call a specific UIViewController
(I called it something like TWLoginVC
) where I do all the Twitter login and other stuff. The view is just black so the user don’t see the process is actually done in another VC (he just has to pick up the Twitter user he wants to login with). I guess you could also put a clear background to be even more invisible.
When I call this view controller and dismiss it, the transition is not applied to it and I don’t have any more problem with it.
EDIT Update for Swift:
DispatchQueue.main.async{
self.present(alertController, animated: true, completion: nil)
}