Home > Software design >  iOS Braintree Dropin ui, throws undeclared identifier 'BTAppSwitch`
iOS Braintree Dropin ui, throws undeclared identifier 'BTAppSwitch`

Time:09-16

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

CodePudding user response:

As you can see in the documentation of the README here,

After you install the correct cocoa pods, at the top of your AppDelegate.m file you need to add this line:

#import "BraintreeCore.h"

and that should get rid of the error. But don't forget to finish all the other initialization steps before building

CodePudding user response:

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

CodePudding user response:

It might be more easy than assumed. V5 renamed BTAppSwitch to BTAppContextSwitcher So try to do this instead:

[BTAppContextSwitcher setReturnURLScheme:@"com.mycompany.myapp.payments"];

Check the Migration guide: https://github.com/braintree/braintree_ios/blob/7c16276901b2ade9804d07facb516be912a7138f/V5_MIGRATION.md

Quote:

v5 renames the BTAppSwitch class to BTAppContextSwitcher to clarify that it is used for flows that requiring switching contexts, either by opening an SFSafariViewController or by opening a different app (specifically, Venmo).

BTAppSwitchDelegate was removed in v5. If you were using these delegate methods to determine when control switched between your app and the Venmo app, we recommend using app or scene delegate methods instead. If you were using BTAppSwitchDelegate to determine when an SFSafariViewController was presented or dismissed, we recommend using the BTViewControllerPresentingDelegate methods instead.

Register your app's custom URL scheme with BTAppContextSwitcher in your app delegate.

This could be the reason why BTAppSwitch couldn't be found

CodePudding user response:

In your AppDelegate, add these two lines at the top:

@import Braintree;
@import BraintreeDropIn;

Cocoapods outputs Objective-C modules, which you have to import with @import.

Separately, if you want to learn a little bit about Objective-C modules (Apple introduced them in WWDC '13) and how it compares to other types of imports, this is a good writeup: https://useyourloaf.com/blog/modules-and-precompiled-headers/

  • Related