2017-05-02 10 views
0

신속하게 3으로 mobilepay라는 이름으로 내 응용 프로그램에 지불 모듈을 구현하려고합니다. 내 애플리케이션의 사용자가 커피 한 잔을 사서 모바일 페이로 구매하면 그는 모바일 페이 애플리케이션에 와서 커피를 사 준다. 그런 다음 응용 프로그램 위임자에서 호출되는 함수 (응용 프로그램 대리자에 배치되기를 요구하는 mobilepay 자체)로 돌아와서 응용 프로그램으로 돌아갑니다. 우리는 같은 말을 시청자에 대한 경고를 실행하려고 할 때 우리는 기본적으로이 오류가 다시 우리의 응용 프로그램에 도착하면 "성공적으로 구입을."응용 프로그램을 다시 열 때 알리미가 표시되지 않습니다.

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 : AppDelegate에의

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 

이 우리의 코드 이 문제를 해결하는 방법을 모른다면 페이지가 제대로로드되기 전에 경고가 호출 된 것 같습니다.

도움을 주시면 감사하겠습니다. 미리 감사드립니다. Sebastian.

+0

어떤 스크린 샷을 가지고를 사용하여 최상위 컨트롤러를 찾아 일을 가지고, 말했다로? –

+0

가장 많이보기 컨트롤러를 찾고 경고 메시지를 표시합니다. –

+0

이 self.window를 바꾸려고합니까? .rootViewController? .present (alertController, animated : true, 완료 : nil) ** ** 으로 UIApplication.shared.keyWindow? .rootViewController ? present (alertController, animated : true, completed : nil) – KKRocks

답변