unrecognized selector sent to instance

Back to How-to Discussions
The issue in this thread has been resolved.

Hi guys , i'm working on the integration of the sumup android and iOS sdk in fusetools. the repository of the module can be found bellow. https://github.com/princefr/Fuse.Sumup

i managed to get the android part fully working. in the iOS part the payment process works pretty well in the Xcode simulator (see the code below), but when i test it with real device (iPod touch) , the checkout process freeze , and it gives me this error '-[uAppDelegate window]: unrecognized selector sent to instance 0x149e02d20'

  [Require("Xcode.Framework", "@('SumupSDK.embeddedframework/SumupSDK.framework':Path)")]
  [Require("Xcode.Framework", "Accelerate")]
  [Require("Xcode.Framework", "AVFoundation")]
  [Require("Xcode.Framework", "MapKit")]
  [Require("Source.Import", "SumupSDK/SumupSDK.h")]
  extern(iOS)
   class PayWithToken: Promise<string>
  {

    [Foreign(Language.ObjC)]
    public  PayWithToken(string accessToken, string productAmount, string productTitle, string foreignRef)
    @{



      [SumupSDK loginWithToken:accessToken
                       completion: ^(BOOL success, NSError *error) {
                           if (error) {
                            @{PayWithToken:Of(_this).Reject(string):Call(@"token non obtenu")};                          
                           }else{

                                  [SumupSDK prepareForCheckout];
      SMPCheckoutRequest *request = [SMPCheckoutRequest requestWithTotal:[NSDecimalNumber decimalNumberWithString:productAmount]
                                                                   title:productTitle
                                                            currencyCode:[[SumupSDK currentMerchant] currencyCode]
                                                          paymentOptions:SMPPaymentOptionAny];

              [request setForeignTransactionID:foreignRef];

              [SumupSDK checkoutWithRequest: request
                          fromViewController: [UIApplication sharedApplication].keyWindow.rootViewController
                                    completion: ^(SMPCheckoutResult *result, NSError *error) {
                                              if(error)
                                          @{PayWithToken:Of(_this).Reject(string):Call(@"Vous devez etre connecter")};
                                                else
                                          @{PayWithToken:Of(_this).Resolve(string):Call(@"Le paiement a été effectué")};
                                        
                }];

        // something went wrong checkout was not started
        if (![SumupSDK checkoutInProgress]) {
           @{PayWithToken:Of(_this).Reject(string):Call(@"Une erreur de connard s'est produite")};
        }


          }

         }];


    @}



    void Resolve(string message)
      {
        base.Resolve(message);
      }

      void Reject(string reason)
      {
        Reject(new Exception(reason));
      }

  }

I think it has something to do with [UIApplication sharedApplication].keyWindow.rootViewController, but didn't find any solution to sort this out. anyone can help me ?

I don't have an immediate solution for you, but the top one and top two results on Google should get you going.

First of all, enable exception breakpoints in XCode and see where it crashes. Then take it from there.

enabling exception breakpoints doesn't help much further to debug this http://prntscr.com/gfcjgp (maybe i'm too weak),

it is complaining about main.mm

#include <Uno/Uno.h>
#include <UIKit/UIKit.h>

#include <Uno-iOS/AppDelegate.h>

int main(int argc, char **argv)
{
    // TODO: Report unhandled exceptions.
    // Can't rely on exceptions propagating outside UIApplicationMain as it
    // won't work with latest arm64 ABI

    @autoreleasepool
    {
        return UIApplicationMain(
            argc, argv, nil, NSStringFromClass([uAppDelegate class]));
    }
}

and fromViewController:[UIApplication sharedApplication].keyWindow.rootViewController is this part of the code who crash.

Hi prince, you have 3 instances of fromViewController: [UIApplication sharedApplication].keyWindow.rootViewController in that file. Which one is the issue? Do the others work?

I got your code to build but don't know how to replicate the issue.

all the

fromViewController: [UIApplication sharedApplication].keyWindow.rootViewController

works on simulation without any problem, the issues occur with real devices, and only on the payment process with my functions Pay and PaywithToken.

Thanks for narrowing down that first part, but the buttons in the app don't seem to do anything when clicked, please describe the process to follow to cause the error to happen.

its a working example, https://www.dropbox.com/s/t8yfy1fohiwu8h8/Archive.zip?dl=0 please add -ObjC to "Other Linker Flags" Add the bundles provided in SumupSDK.embeddedframework/Resources to your app target.

SumupSDK.embeddedframework/Resources/SMPSharedResources.bundle
 SumupSDK.embeddedframework/Resources/YTLibResources.bundle

you have to specify the 3 input (the first is the amount) before pressing the bouton PayWithToken.

That archive looks very similar to the github repo you linked at the top. Are they the same? If so can't I just use the repo?

You can use the repo , but the archive have all credentials needed already filled , so its ready to go.

It ran but the button just logs haha i started to the console and nothing else happens. I am happy to test other versions you provide (especially if it was a more minimal test case).

the token take a bit time to be retrieved. but it should work normally, hum i'm building a minimal test case

for the price I entered 100, for the foreigncode I enetered 'a', for the title I entered 'b'

This is the result on the iPhone 6plus running iOS 9.3.2

2017-09-01 13:45:34.670 test[540:313470] "haha i started"
2017-09-01 13:45:35.006 test[540:313470] {"type":"default","status":200,"ok":true,"statusText":"OK","headers":{"map":{"status":["200 OK"],"x-content-type-options":["nosniff"],"content-type":["application/json; charset=utf-8"],"server":["nginx"],"connection":["keep-alive"],"date":["Fri, 01 Sep 2017 11:45:34 GMT"],"x-download-options":["noopen"],"x-frame-options":["SAMEORIGIN"],"x-xss-protection":["1; mode=block"],"content-length":["303"],"etag":["W/\"12f-XTnIGBvMCwYrRS1VhojLTMAVk9Y\""]}},"url":"","_bodyInit":"{\"access_token\":\"3067c162c3893489c62ede3c716ee9e343a52d56460b9df1cec66f4f8acff1e1\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"c288e6ab55bc7e8d4097705622ee9aa1898bec074c063855fd72e98d0247b3a1\",\"scope\":\"payments user.app-settings transactions.history user.profile_readonly user.subaccounts\"}","_bodyText":"{\"access_token\":\"3067c162c3893489c62ede3c716ee9e343a52d56460b9df1cec66f4f8acff1e1\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"c288e6ab55bc7e8d4097705622ee9aa1898bec074c063855fd72e98d0247b3a1\",\"scope\":\"payments user.app-settings transactions.history user.profile_readonly user.subaccounts\"}"}
2017-09-01 13:45:36.332 test[540:313470] "token non obtenu"

This is the result on the iPhone 6 running iOS 10.3.2

1144316255_PortraitChoco_iPhone-Simple-Pad_Default
2017-09-01 13:47:23.162153+0200 test[1747:1492477] "haha i started"
2017-09-01 13:47:23.785709+0200 test[1747:1492477] {"type":"default","status":200,"ok":true,"statusText":"OK","headers":{"map":{"status":["200 OK"],"x-content-type-options":["nosniff"],"content-type":["application/json; charset=utf-8"],"server":["nginx"],"etag":["W/\"12f-F9JdF/rOlQB/0gr3UuI0EEfg7jk\""],"date":["Fri, 01 Sep 2017 11:47:23 GMT"],"x-download-options":["noopen"],"x-frame-options":["SAMEORIGIN"],"x-xss-protection":["1; mode=block"],"content-length":["303"],"connection":["keep-alive"]}},"url":"","_bodyInit":"{\"access_token\":\"95764a94dc65d2d951f82f439a1b2bc2793b8f4efc349b124792951e4b36fc8d\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"ed17db8c203e74e0ad54feb67ed401548d290339e53e281640b1ab64764990e9\",\"scope\":\"payments user.app-settings transactions.history user.profile_readonly user.subaccounts\"}","_bodyText":"{\"access_token\":\"95764a94dc65d2d951f82f439a1b2bc2793b8f4efc349b124792951e4b36fc8d\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"ed17db8c203e74e0ad54feb67ed401548d290339e53e281640b1ab64764990e9\",\"scope\":\"payments user.app-settings transactions.history user.profile_readonly user.subaccounts\"}"}
2017-09-01 13:47:33.710413+0200 test[1747:1492477] "token non obtenu"

Sadly not the crash you mentioned before. Any ideas?

token non obtenu is my error when login with token fails, seems like you are already logged in, as sumup dont provide a good error to manage this (the error is null), the best to do for testing here is to change my line 54 in iOSImpl.uno to if (error == NULL) the first payment will fail but next ones will works. this is a video of my test on simulation. https://www.youtube.com/watch?v=ooQZLztQ3dI as you can see , it works pretty well on simulation , in the device , it freeze when the modal payment open

Changling like 54 to if (error==NULL) { just causes a different exception:

2017-09-07 11:25:28.273 test[795:1054760] SumupSDK: Ignoring 'prepareForCheckout'. Not logged in.
2017-09-07 11:25:28.273 test[795:1054760] SumupSDK: Not presenting checkout as user is not logged in.
libc++abi.dylib: terminating with uncaught exception of type uThrowable: Uno.Exception

Which makes a lot of sense to be honest.

this is not the error i get as shown on the video the checkout is presented and i'm each time connected

I openned a issue on the sumup side for this error. this is the link. https://github.com/sumup/sumup-ios-sdk/issues/50

the sumup developper is asking if uAppDelegate has a window property or method;

this is my code updated to test again. has responded the function should not complaining about to be logged to make a payment as each times you call the function it first log you in with a token before trying to make a payment.

      [SumupSDK loginWithToken:accessToken
                       completion: ^(BOOL success, NSError * _Nonnull error) {
                           if (error.code != 22 && error != NULL) {
                            NSLog(@"%@", error);
                            @{PayWithToken:Of(_this).Reject(string):Call(@"token not found")};                          
                           }else{

                            [SumupSDK prepareForCheckout];
      SMPCheckoutRequest *request = [SMPCheckoutRequest requestWithTotal:[NSDecimalNumber decimalNumberWithString:productAmount]
                                                                   title:productTitle
                                                            currencyCode:[[SumupSDK currentMerchant] currencyCode]
                                                          paymentOptions:SMPPaymentOptionAny];

              [request setForeignTransactionID:foreignRef];

              [SumupSDK checkoutWithRequest: request
                          fromViewController: [UIApplication sharedApplication].keyWindow.rootViewController
                                    completion: ^(SMPCheckoutResult *result, NSError *error) {
                                              if(error){
                                            @{PayWithToken:Of(_this).Reject(string):Call(@"you need to be connected to make a payment")};
                                              }else{
                                              @{PayWithToken:Of(_this).Resolve(string):Call(@"Le paiement a été effectué")};
                                            }
                                                                 
                }];

        // something went wrong checkout was not started
        if (![SumupSDK checkoutInProgress]) {
           @{PayWithToken:Of(_this).Reject(string):Call(@"Une erreur de connard s'est produite")};
        }


          }

         }];

i really need to get this module working for both side (android and iOS) as we are planning to launch our fuse app soon.

2017-09-14 13:01:41.409 test[1107:1969075] "haha i started"
2017-09-14 13:01:41.512 test[1107:1969075] {"type":"default","status":200,"ok":true,"statusText":"OK","headers":{"map":{"status":["200 OK"],"x-content-type-options":["nosniff"],"content-type":["application/json; charset=utf-8"],"server":["nginx"],"connection":["keep-alive"],"date":["Thu, 14 Sep 2017 11:01:41 GMT"],"x-download-options":["noopen"],"x-frame-options":["SAMEORIGIN"],"x-xss-protection":["1; mode=block"],"content-length":["303"],"etag":["W/\"12f-HUKuemol4Sw7orGDLH4otkd8CQE\""]}},"url":"","_bodyInit":"{\"access_token\":\"23d8062c3735f7351d931f97c4b7dfb35495fb2b7ffad831825c7db43f75c3d0\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"f8dcfcbe7805f4aa73ee3a3ebdc4a9cd2f93712f5e5088cfd1647382cd50d88f\",\"scope\":\"payments user.app-settings transactions.history user.profile_readonly user.subaccounts\"}","_bodyText":"{\"access_token\":\"23d8062c3735f7351d931f97c4b7dfb35495fb2b7ffad831825c7db43f75c3d0\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"refresh_token\":\"f8dcfcbe7805f4aa73ee3a3ebdc4a9cd2f93712f5e5088cfd1647382cd50d88f\",\"scope\":\"payments user.app-settings transactions.history user.profile_readonly user.subaccounts\"}"}
2017-09-14 13:01:41.676 test[1107:1968972] Error Domain=SumupSDKError Code=20 "(null)" UserInfo={NSUnderlyingError=0x1498e8010 {Error Domain=JSONRPCServerError Code=-32006 "Version not supported" UserInfo={NSLocalizedDescription=Version not supported, JSONObject={
    code = "-32006";
    data =     {
        message = "Sorry, but we've experienced an unexpected error. Please try closing the app and logging in again, or contact our Support Team (quote: UKN-W61QY)";
    };
    message = "Version not supported";
}}}}
2017-09-14 13:01:41.682 test[1107:1969075] "token not found"

Sorry prince this does not reproduce the issue. We really want to help you fix the error so you can ship, but without being able to get to the actual issue we just can't help. Happy to test a smaller example of the error or to keep trying with this one.

[uAppDelegate window]: unrecognized selector sent to instance One thing I don't understand is why you are using the uAppDelegate for you callback as it will not have the selector you need. You probably will have more luck making an object that implements the protocol the system requires and using that instead.

To be clear uAppDelegate does not have window. So the routine is failing

Thank you for your time on this. will try to build the object needed, if you guys have some ressources or fuselibs things who do the same (init object like this in uno) this will be helpful for me. sumup is available in few countries maybe this is why you are running on this issue.

Post Stats
  • 26
    replies
  • 2487
    views
  • 3
    users
Frequent Posters