2016-06-15 9 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:アラートの機能は問題なく、他の関数から呼び出されます。

どうすればこの問題を解決できますか?この参考になっポストへ

+0

からpresentViewControllerを作るために、アラート機能を変更している私はpaymentQueueRestoreCompletedTransactionsFinishedから新しいビューを表示しようとしましたが、持っています同じ種類のメッセージ... – Ludo

答えて

0

ありがとう: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){} 

    } 

} 
関連する問題