2017-05-02 1 views
0

J'essaie d'implémenter un module payant à mon application dans swift 3 avec le nom de mobilepay. Quand un utilisateur sur mon application a acheté une tasse de café et appuie sur acheter avec mobilepay, il vient à l'application mobilepay, où il achète la tasse de café. Puis il est renvoyé à notre application après avoir fait son truc, qui revient avec une fonction qui est appelée dans notre délégué d'application (mobilepay lui-même a demandé que cela soit placé dans le délégué de l'application). Quand nous retournons à notre application, nous obtenons essentiellement cette erreur lors d'une tentative exécuter une alerte pour le spectateur en disant comme « achat réussi. »:alerte ne montre pas lors de la réouverture de l'application

MobilePay purchase succeeded: Your have now paid for order with id 123456 and MobilePay transaction id 123456789and the amount withdrawn from the card is: 10.0 
2017-05-01 09:05:57.797628+0200 Keebin_development_1[262:10533] Warning: Attempt to present <UIAlertController: 0x16ba0e00> on <Keebin_development_1.LoginViewController: 0x15e91d40> whose view is not in the window hierarchy! 
2017-05-01 09:05:59.033882+0200 Keebin_development_1[262:10533] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction 

ce notre code appdelegate:

func alert(message: String, title: String = "") { 
     let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) 
     let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil) 
     alertController.addAction(OKAction) 
     self.window?.rootViewController?.present(alertController, animated: true, completion: nil) 
    } 


func application(_ app: UIApplication, open url: URL, options: [String: Any]) -> Bool { 


     handleMobilePayPayment(with: url) 
     return true 
    } 
func handleMobilePayPayment(with url: URL) { 
     MobilePayManager.sharedInstance().handleMobilePayPayment(with: url, success: {(mobilePaySuccessfulPayment: MobilePaySuccessfulPayment?) -> Void in 
      let orderId: String = mobilePaySuccessfulPayment!.orderId 
      let transactionId: String = mobilePaySuccessfulPayment!.transactionId 
      let amountWithdrawnFromCard: String = "(mobilePaySuccessfulPayment!.amountWithdrawnFromCard)" 
      print("MobilePay purchase succeeded: Your have now paid for order with id (orderId) and MobilePay transaction id (transactionId) and the amount withdrawn from the card is: (amountWithdrawnFromCard)") 
      self.alert(message: "You have now paid with MobilePay. Your MobilePay transactionId is (transactionId)", title: "MobilePay Succeeded") 
     }, error: {(error: Error?) -> Void in 
//   let dict: [AnyHashable: Any]? = error?.userInfo 
//   let errorMessage: String? = (dict?.value(forKey: NSLocalizedFailureReasonErrorKey) as? String) 
//   print("MobilePay purchase failed: Error code '(Int(error?.code))' and message '(errorMessage)'") 
//   self.alert(message: errorMessage!, title: "MobilePay Error (error?.code as! Int)") 
      self.alert(message: error as! String) 
      //TODO: show an appropriate error message to the user. Check MobilePayManager.h for a complete description of the error codes 
      //An example of using the MobilePayErrorCode enum 
      //if (error.code == MobilePayErrorCodeUpdateApp) { 
      // NSLog(@"You must update your MobilePay app"); 
      //} 
     }, cancel: {(_ mobilePayCancelledPayment: MobilePayCancelledPayment?) -> Void in 
      print("MobilePay purchase with order id (mobilePayCancelledPayment?.orderId!) cancelled by user") 
      self.alert(message: "You cancelled the payment flow from MobilePay, please pick a fruit and try again", title: "MobilePay Canceled") 
     }) 
    } 

I ne sais pas comment résoudre ce problème, il semble que l'alerte est appelée avant que la page est chargée correctement?

Toute aide serait grandement appréciée. Merci d'avance, Sebastian.

+0

Vous avez des capture d'écran? –

+0

trouver le plus haut contrôleur de vue et de présenter votre alerte –

+0

essayer de remplacer cette auto.window? .rootViewController? .present (alertController, animé: vrai, achèvement: nil) ** Avec ** UIApplication.shared.keyWindow? .rootViewController ? .present (alertController, animé: true, completion: nul) – KKRocks

Répondre