Search code examples
iosobjective-creact-nativepaypalbraintree

iOS Braintree Dropin ui, throws undeclared identifier 'BTAppSwitch`


I am using the Braintree drop-in ui for React Native. My issue seems maybe not specific to the library, in which I have already created an issue.

I'm at the point where I need to add my setReturnURLScheme to my AppDelegate.m

Looks like this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [BTAppSwitch setReturnURLScheme:@"com.mycompany.myapp.payments"];
  //...
}

However, I receive an error with BTAppSwitch, it says Use of undeclared identifier 'BTAppSwitch'.

As far as I can tell, I have installed and linked all pods appropriately/automatically, but most instructions are pretty brief. Seems like maybe I'm missing an import statement, but none I've tried have helped. Can someone help please?

I am using v4


Solution

  • You need to import the following in your AppDelegate.m file

    #import "BraintreeCore.h"
    

    Make sure you've used the correct bundle identifier as follows

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      [BTAppSwitch setReturnURLScheme:@"yourappbundleidentifier.payments"];
      return YES;
    }
    

    and your info.plist must includes this

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>yourappbundleidentifier.payments</string>
            </array>
        </dict>
    </array>
    

    In case you're still facing the issue while archiving the app in xcode. Make sure

    #import "BraintreeCore.h"
    

    must be placed before this line of code

    #ifdef FB_SONARKIT_ENABLED
    

    Hope this will resolve your issues