iOS Braintree Dropin ui,抛出未声明的标识符“BTAppSwitch”

iOS Braintree Dropin ui, throws undeclared identifier 'BTAppSwitch`

我正在为 React Native 使用 Braintree 插件 ui。我的问题似乎不是特定于库的,我已经在其中创建了一个问题。

我现在需要将我的 setReturnURLScheme 添加到我的 AppDelegate.m

看起来像这样

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

但是,我收到 BTAppSwitch 的错误消息,显示 Use of undeclared identifier 'BTAppSwitch'

据我所知,我已经安装并链接了所有 pods appropriately/automatically,但大多数说明都非常简短。似乎我遗漏了导入语句,但 none 我试过有帮助。有人可以帮忙吗?

我正在使用 v4

这可能比想象的要容易。 V5 将 BTAppSwitch 重命名为 BTAppContextSwitcher 所以尝试这样做:

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

查看迁移指南: https://github.com/braintree/braintree_ios/blob/7c16276901b2ade9804d07facb516be912a7138f/V5_MIGRATION.md

引用:

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.

这可能是找不到 BTAppSwitch 的原因

在您的 AppDelegate 中,在顶部添加这两行:

@import Braintree;
@import BraintreeDropIn;

Cocoapods 输出 Objective-C 个模块,您必须使用 @import.

导入这些模块

另外,如果您想稍微了解一下 Objective-C 模块(Apple 在 WWDC '13 中介绍了它们)以及它与其他类型的导入的比较,这是一篇很好的文章:https://useyourloaf.com/blog/modules-and-precompiled-headers/

如您在 README here

的文档中所见

安装正确的 cocoa pods 后,您需要在 AppDelegate.m 文件的顶部添加此行:

#import "BraintreeCore.h"

这应该可以消除错误。但是不要忘记在构建之前完成所有其他初始化步骤

您需要在 AppDelegate.m 文件中导入以下内容

#import "BraintreeCore.h"

确保您使用了正确的包标识符,如下所示

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

并且您的info.plist必须包括这个

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

如果您在 xcode 中存档应用程序时仍然遇到问题。确保

#import "BraintreeCore.h"

必须放在这行代码之前

#ifdef FB_SONARKIT_ENABLED

希望这能解决您的问题