Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate method not invoked #383

Closed
aodhol opened this issue Jan 22, 2018 · 15 comments
Closed

Delegate method not invoked #383

aodhol opened this issue Jan 22, 2018 · 15 comments

Comments

@aodhol
Copy link

aodhol commented Jan 22, 2018

General information

  • SDK/Library version: 4.10.0
  • Environment: Sandbox
  • iOS Version and Device: 11.2 iPhone 7 simulator / device.
  • Integration type and version: Cocoapods 1.4.0 b2

Issue description

Delegate methods not getting invoked even though the SafariViewController is shown and dismissed via the big blue button.

`

 func paypalButtonTapped(_ sender: UIButton) {

    guard let braintreeClient = braintreeClient else {
        return
    }
    
    let payPalDriver = BTPayPalDriver(apiClient: braintreeClient)
    payPalDriver.viewControllerPresentingDelegate = self
    payPalDriver.appSwitchDelegate = self
    let payPalRequest = BTPayPalRequest(amount: "29.99")
    payPalDriver.requestOneTimePayment(payPalRequest) { (tokenizedPayPalAccount, error) -> Void in
         // do stuff...
    }
 }

`

@demerino
Copy link
Member

@aodhol
See: #361 (comment)

On iOS11+ a SFAuthenticationSession is used for PayPal payments and does not require the delegate methods for presentation/dismissal.

Let us know if you have additional questions or feedback.

@aodhol
Copy link
Author

aodhol commented Jan 22, 2018 via email

@demerino
Copy link
Member

@aodhol This makes sense. In this case, we would likely need to add a new generic lifecycle event that isn't coupled to app switching or presentation/dismissal. We'll look into this.

@aodhol
Copy link
Author

aodhol commented Jan 22, 2018

@demerino shall I leave this open then?

@demerino
Copy link
Member

Yes, we appreciate the feedback!

@demerino
Copy link
Member

demerino commented Apr 3, 2018

@aodhol 4.14.0 has added new BTAppSwitchDelegate methods which should work across all possible app switch scenarios.

Switch: http://braintree.github.io/braintree_ios/Protocols/BTAppSwitchDelegate.html#/c:objc(pl)BTAppSwitchDelegate(im)appContextWillSwitch:

Return: http://braintree.github.io/braintree_ios/Protocols/BTAppSwitchDelegate.html#/c:objc(pl)BTAppSwitchDelegate(im)appContextDidReturn:

@demerino demerino closed this as completed Apr 3, 2018
@aodhol
Copy link
Author

aodhol commented Apr 4, 2018

@demerino I've tested this on the BTPayPalDriver and can't get any of the delegate methods to trigger...

@ancafeurdean09
Copy link

@aodhol did you implement the BTAppSwitchDelegate? I tested myself and it works for me, both of the methods are getting called

@aodhol
Copy link
Author

aodhol commented Apr 4, 2018 via email

@ancafeurdean09
Copy link

I followed the steps described in here: https://developers.braintreepayments.com/guides/paypal/client-side/ios/v4 when I first implemented this and now I just added those methods for testing purposes and I saw it's working fine, at least for me

@aodhol
Copy link
Author

aodhol commented Apr 4, 2018 via email

@demerino
Copy link
Member

demerino commented Apr 4, 2018

@ancafeurdean09 @aodhol Thanks for trying out the new methods.

I'm not sure why it isn't working for aodhol. Can you share the methods you implemented and the code snippet where you set the delegate?

@aodhol
Copy link
Author

aodhol commented Apr 4, 2018

func paypalButtonTapped(_ sender: UIButton) {

        guard let braintreeClient = braintreeClient else {
            return
        }

        let payPalDriver = BTPayPalDriver(apiClient: braintreeClient)
        payPalDriver.viewControllerPresentingDelegate = self
        payPalDriver.appSwitchDelegate = self
        let payPalRequest = BTPayPalRequest(amount: "29.99")
        payPalDriver.requestOneTimePayment(payPalRequest) { (tokenizedPayPalAccount, error) -> Void in
        
            if let error = error {
               // .. handle error.
            }

            guard let tokenizedPayPalAccount = tokenizedPayPalAccount else {
                    return
            }

            // Post nonce to server ...

        }
    }

The delegate is in an extension on the view controller as follows:

extension ShoppingCartViewController: BTAppSwitchDelegate {
    func appSwitcherWillPerformAppSwitch(_ appSwitcher: Any) {
        print("appSwitcherWillPerformAppSwitch")
    }
  
    func appSwitcher(_ appSwitcher: Any, didPerformSwitchTo target: BTAppSwitchTarget) {
        print("didPerformSwitchTo")
    }
    
    func appSwitcherWillProcessPaymentInfo(_ appSwitcher: Any) {
         print("appSwitcherWillProcessPaymentInfo")
    }
}

@demerino
Copy link
Member

demerino commented Apr 4, 2018

I don't see the new optional delegate methods: appContextWillSwitch: and appContextDidReturn:.

    func appContextWillSwitch(_ appSwitcher: Any) {
        print("appContextWillSwitch")
    }
.....

@aodhol
Copy link
Author

aodhol commented Apr 4, 2018

@demerino that was the problem :[ Thanks, and sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants