Implement custom Cancel Button in a SDK
Asked Answered
P

1

8

I want to implement payment functionality with paysbuy SDK....The problem is it doesnot have any cancel option on it so that user can cancel the operation of close after the payment has been successful.

By default SDK provides a method that opens the default WebView that covers the whole part of the screen..And there is no any cancel option..

I just want to add a cancel button by load the payment on the specific view..or viewcontroller..I tried using in container view..to load the view inside the container view and a cancel button outside the container view ,but when i try this process,it shows by default in Full Screen WebView.Also tried creating a PopUP but didnot succeed

So, how can i load the webview of SDK on a specific portion of my view so that i can put a Cancel button??

This is the method that the sdk provides to start the service

- (void) callServiceWithCurrentView :(UIViewController *) currentViewController
                             invoice:(NSString *)invoice
                                item:(NSString *)item
                              amount:(NSString *)amount
                       paypal_amount:(NSString *)paypal_amount
                      transferMethod:(NSString *)transferMethod
                    customerLanguage:(NSString *)customerLanguage
                       operator_name:(NSString *)operator_name
                      operator_email:(NSString *)operator_email
                     operator_mobile:(NSString *)operator_mobile
                    operator_address:(NSString *)operator_address
                     operator_detail:(NSString *)operator_detail;

Here we can see the callServiceWithCurrentView method shows the target as currentviewcontroller so i think it loads by default in full screen mode on the viewcontroller....

Here is how i implemented in swift

   paysBuy?.callServiceWithCurrentView(self, invoice: "343434343", item: "App Fee", amount: "10", paypal_amount: "1", transferMethod: "1", customerLanguage: "E", operator_name: "PAYSBUY", operator_email: "[email protected]", operator_mobile: "0888888888", operator_address: "PAYSBUY.COM", operator_detail: "PAYMENT")

And a delegate method that handles the response in case of success or failutre

extension PaysBuyHelper:PaysbuySDKDelegate{
    func responseWithResult(result: String!, andInvoice invoice: String!) {

        //here is the response of the payement

        println(result)
        println(invoice)

        if result == "00" {

            println("transaction complete and below is the invoice number")
            println(invoice)

        }else if result == "90"{

            println("transaction incomplete information")

        }

    }

}

Here is the work that i have done.... https://drive.google.com/file/d/0Bzk4QVQhnqKmVno5NGdPUV9ITkE/view?usp=sharing

Panathenaea answered 17/8, 2015 at 6:43 Comment(5)
you can't add cancel button on webview because you don't have any control over it, one solution that I think to solve this problem is you have to pass a another UIViewController instead of self in the function and try to make the second UIViewController as a popup with less height or similar like thisRecept
@VarunNaharia The issue seems to be that the SDK being used replaces the root controller. Hence there is no way to control what is on screen as it takes over.Quench
@VarunNaharia i tried doing as you said but it didnot work well...it shows me default in full screen..tried using on popup,container view and as rory told in the answer..but none of them workPanathenaea
Try this #17758920 and try to make a button top of every viewRecept
i have already tried using container view...Panathenaea
Q
7

Modal controllers are presented within the frame context of the controller which is deemed to define the presentation context.

An option you have is to make the controller which calls callServiceWithCurrentView define the context for any modal presentation which can then be used to restrict the area on screen that is used.

You do this in XCode by clicking on your presenting controller and selecting the Defines Context checkbox. In code you can set the definesPresentationContext to TRUE.

For this to be of use to you, you need the frame for the presenting controller to not be full screen. The ideal situation would be that this is a controller inside a UINavigationController.

Options:

1) Your presenting controller is inside a navigation controller with a navigation bar. Effectively it is a child controller. The screen footprint it uses is dependent on whether it goes under the top and bottom bars. a) Set your controller so that content does not go under the top bars. This effectively makes the frame under the navigation bar. b) When you call callServiceWithCurrentView, add a cancel button on the navigation bar. c) If you set the controller to define the presentation context properly, then the UIWebView should show up under the navigation bar and you can see your new cancel button.

2) If not in a navigation controller, then rather than calling the method directly, add a child controller inside a sub view above which you put your cancel button. Have this child controller do the call callServiceWithCurrentView. Following the same mechanism, make this child controller define the context. Any modal UIWebView should then only cover the area of the child controller.

Hope this gives you some options.

Quench answered 20/8, 2015 at 15:23 Comment(5)
i tried the first way but not working drive.google.com/file/d/0Bzk4QVQhnqKmb04wTTVsT3ZOQUU/…Panathenaea
@copeME I tried option 2 for you as well and no joy. Looking deeper, it seems that the paysbuy SDK is not presenting modally but appears to be completely replacing the root controller. This is why the screen changes quickly. Also if you look using the 3D view hierarchy tool, the original controllers are not behind it. Sadly I think this means there is not much you can do except contact the SDK authors. Its odd that they would create an SDK which removes all control from the presenter. It seems the only way back is to pay 8^).Quench
yeah i tried the 3d view and there was not seen hierarchy....even users pay successfully i dont think the view will be dismissed..???Panathenaea
@copeME Yes seems broken. Where did you get the SDK code from? I could not find it online. You need the code for callServiceWithCurrentView or a fix from the author.Quench
i wrote an email to paysbuy and they send me the sdk...i too wrote and email telling how to figure the cancel option but there was no reply...Panathenaea

© 2022 - 2024 — McMap. All rights reserved.