1

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

SeanMC
  • 1,960
  • 1
  • 22
  • 33

4 Answers4

3

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

Tauqeer H.
  • 781
  • 1
  • 9
  • 20
  • 2
    My issue was needing to put the`#import "BraintreeCore.h"` _before_ the `FB_SONARKIT_ENABLED` condition. I was just putting it at the end of my imports which was after that. – SeanMC Aug 27 '21 at 01:18
  • 1
    Exactly! Happens to me all the time! :D I should have mentioned that specifically! :) – Saamer Aug 27 '21 at 21:21
  • 1
    Wow. Just wow. Upgrading to a new version of React Native had some imports placed under the conditional build directive and it took us an entire day to realize that – jsan Sep 16 '21 at 23:39
1

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

Saamer
  • 4,687
  • 1
  • 13
  • 55
0

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

Pat_Morita
  • 3,355
  • 3
  • 25
  • 36
  • Yes I saw that. I tried that before realizing that my project is built around version 4 – SeanMC Aug 22 '21 at 12:18
  • Then please show us how you include the files. Did you do Standard cleanup stuff like clear product, restart, clear derived data? – Pat_Morita Aug 22 '21 at 12:39
  • Actually, how can I confirm which version? Also, I'm not currently doing any Imports in this file. None of the ones I had tried made any difference. Like, Import "Braintree Core.h". What can I try a? Can you tell me more about clearing derived data? – SeanMC Aug 22 '21 at 12:48
  • The podfile.lock file keeps track of all pods and versions. Check that in a text editor or use the command "cat Podfile.lock" on the terminal in the right directory. Check this on how to delete derived data: https://stackoverflow.com/questions/38016143/how-can-i-delete-derived-data-in-xcode-8. For Cocoapods your podfile must include "pod 'Braintree'". On how to include the headerfiles/framework correctly check the demo which is included in the project. – Pat_Morita Aug 22 '21 at 13:38
  • Which demo/project? – SeanMC Aug 22 '21 at 13:51
  • Once installed via cocoapods, open Braintree.xcworkspace – Pat_Morita Aug 22 '21 at 14:24
  • General question. Is this the first time you work with cocoapods? Do you work inside the xcodeproject file or xcworkspace file? – Pat_Morita Aug 22 '21 at 14:27
  • Hardly ever before. The instructions for this part of the library are like, install and add this line. Add the line, I get an error. – SeanMC Aug 22 '21 at 16:37
  • Do you work in the project file or workspace file? – Pat_Morita Aug 22 '21 at 19:41
0

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/

pietrorea
  • 841
  • 6
  • 14