2016-06-15 2 views
0

나는 아래의 코드를 구현하지만 난 경고 메시지가 :Swift 지불 방법 알림을 표시하는 방법 QueueRestoreCompletedTransactionsFinished?

경고 :에 그보기 창 계층 구조에없는 제시하는 시도를! paymentQueueRestoreCompletedTransactionsFinished (큐 : SKPaymentQueue)에

및 경고가 표시되지 않습니다.

func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue) { 
    alert("Félicitations", message: "Vous avez restauré vos packs, cliquez sur ok pour les télécharger !") 

} 

func alert(title:String, message:String = "") { 
    let alert = UIAlertController(title: title, message:message, preferredStyle: .Alert) 
    alert.addAction(UIAlertAction(title: "OK", style: .Default) { _ in 
     if title == "Félicitations" { 
      let next = self.storyboard?.instantiateViewControllerWithIdentifier("TelechargementVC") as! TelechargementViewController 
      self.presentViewController(next, animated: true, completion: nil) 

     } 

     }) 
    self.presentViewController(alert, animated: true){} 

} 

NB : 내가 전화를 회전 할 경우, 경고가 바로 회전 [/ 편집] 여기

후에 표시되는 [편집] 내 코드 경고 기능이 문제없이 다른 함수에서 호출 .

어떻게 해결할 수 있습니까? 이 helpfull 포스트에

+0

나는 paymentQueueRestoreCompletedTransactionsFinished에서 새로운 뷰를 보여 주려고하고 가지고있다 같은 종류의 메시지 ... – Ludo

답변

0

감사 : 내가 거기에서 presentViewController을 최상위 뷰 컨트롤러를 얻을 수 있도록 알림 기능을 변경 한 https://stackoverflow.com/a/26667122/5030969

func alert(title:String, message:String = "") { 

    if var topController = UIApplication.sharedApplication().keyWindow?.rootViewController { 
     while let presentedViewController = topController.presentedViewController { 
      topController = presentedViewController 
     } 
     // topController should now be your topmost view controller 
     let alert = UIAlertController(title: title, message:message, preferredStyle: .Alert) 
     alert.addAction(UIAlertAction(title: "OK", style: .Default) { _ in 
      if title == "Félicitations" { 
       let next = self.storyboard?.instantiateViewControllerWithIdentifier("TelechargementVC") as! TelechargementViewController 
       topController.presentViewController(next, animated: true, completion: nil) 

      } 
     }) 

     topController.presentViewController(alert, animated: true){} 

    } 

} 
관련 문제