首页 > 解决方案 > 未能尝试在我的 Swift 项目中使用带有桥接头的 Objective-C 库

问题描述

我想我已经完成了所有必要的步骤,但由于某种原因它失败了。这是我得到的错误:

显示所有消息未定义符号:_OBJC_CLASS_$_HCKBeaconCentralManager

在此处输入图像描述

我在构建设置中设置了文件:

在此处输入图像描述

这是桥文件的内容:

#import "HCKBeaconCentralManager.h"
#import "HCKBeaconInterface.h"
#import "HCKBeaconBaseModel.h"
#import "HCKBeaconProtocol.h"

以防万一这是我用来尝试调用 SDK 类的代码:

import UIKit
import SwiftUI
import CoreLocation
import CoreBluetooth

@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate,HCKCentralScanDelegate {

    func centralManagerScanNewDeviceModel(_ beaconModel: HCKBeaconBaseModel!, manager: HCKBeaconCentralManager!) {
        print("centralManagerScanNewDeviceModel")
    }

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        print("scene init")
        HCKBeaconCentralManager.sharedInstance()?.scanDelegate = self
    }

    func sceneDidDisconnect(_ scene: UIScene) {
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
    }

    func sceneWillResignActive(_ scene: UIScene) {
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
    }
}

标签: objective-cswiftobjective-c-swift-bridge

解决方案


将您的 Objective-C 文件添加到 Xcode->Targets->Build Phases->Compile Sources。


推荐阅读