【发布时间】:2021-03-16 18:48:23
【问题描述】:
我正在将一个 ObjC 静态库导入到我的 ObjC 应用程序中,但出现 95 个与 swift 相关的构建错误。
ObjC 静态库构建正常,包含 .m .h 和 .swift 源文件。
Swift 文件导入 CoreBluetooth。
以下内容...
- 构建错误
- 源代码文本
- 项目压缩包,应 Asperi 的友好请求
更新 2
更新 3
..1.这里 Xcode 构建错误加上必要的源代码............
..2.源码正文
// OBJC APP
// ViewController.h
// sim_backend_UI
//
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Mobile_Sensor_API.h"
@interface ViewController : UIViewController
@end
// OBJC APP
// ViewController.m
// sim_backend_UI
//
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
Mobile_Sensor_API* mobile_sensor_API;
if( !mobile_sensor_API ) mobile_sensor_API = [[ Mobile_Sensor_API alloc] init];
// Tell Mobile_Sensor_API library to start BLE central scanning:
[ mobile_sensor_API _init_and_test ];
}
@end
// OBJC STATIC LIB with some Swift
// mobile_sensor_API.h
#import <Foundation/Foundation.h>
@interface Mobile_Sensor_API : NSObject
-(int)_init_and_test;
@end
// OBJC STATIC LIB with some Swift
// mobile_sensor_API.m
//
//
// ObjC...
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
// app...
#import "mobile_sensor_API.h"
#import "mobile_sensor_API-Swift.h"
//#define BUILD_SIM_MOBILE_HUB ' builds sim mobile_hub
@interface Mobile_Sensor_API()
@property BLE_Central* BLE_central_instance;
@end
@implementation Mobile_Sensor_API
// Init Maestro lib at boot time and test interface with backend:
-(int)_init_and_test
{
// Init access to Swift:
_BLE_central_instance = [[ BLE_Central alloc] init];
// Start BLE:
[ _BLE_central_instance start_central ];
return 1;
}
@end
/*
// OBJC STATIC LIB with some Swift
Abstract:
A class to discover, connect, receive notifications and write data to sensor peripherals by using a
transfer service and characteristic.
*/
//import Foundation
import UIKit
import CoreBluetooth
import os
var centralManager: CBCentralManager = CBCentralManager()
@objc open class BLE_Central
: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
{
var discoveredPeripheral: CBPeripheral?
var transferCharacteristic: CBCharacteristic?
var writeIterationsComplete = 0
var connectionIterationsComplete = 0
let defaultIterations = 5 // change this value based on test usecase
var data = Data()
@objc public func start_central()
{
os_log("Central_class: start_central")
mobile_sensor_API.centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])
os_log("Scanning started")
}
. . .
更新 1 -- 2020 年 12 月 5 日...
我从 mac OS 压缩了两个项目 sim_backend_UI 和 mobile_sensor_API。
您需要使用您的... 目标 > 签约 > 团队 和 TARGETS > Build Settings > All > Packaging > Product Bundle Identifier
..因为我从他们那里删除了我们的公司。
更新 2 - 十二月。 6 条已删除
更新 3 - 十二月。 7 回答了 1
我从 Asperi 获得答案 1 的步骤...
1. Created workspace at top folder
1.1 Copied clean app and lib to top folder
2. Add mobile_sensor_API.xcodeproj to workspace
3. Add sim_backend_UI.xcodeproj to workspace
4. Added dependency of sim_backend_UI to lib via workspace
a. sim_backend_UI proj > General tab > Frameworks, Libs.. > +
b. Select libmobile_sensor_API.a
c. Add.
5. Add Some.swift (any swift file you want) to sim_backend_UI, just for the purpose Xcode add required system swift dynamic libraries (which will be needed for swift part in static library as well)... and confirm creating bridge in appeared dialog
a. new file > Swift > Some.swift
b. Create Bridging Header
c. Added to Some.swift ...
import Foundation
struct Some{}
d。将 mobile_sensor_API.h 拖入 app proj nav e.将 Xcode “活动方案”设置为应用项目和设备
6. Build
I got "succeeded" and it runs on iphone.
【问题讨论】:
-
我认为这不是代码,而是项目设置问题。您会以某种方式授予对项目的访问权限吗?
-
Asperi:我刚刚添加了对项目的访问权限。从此链接下载项目:drive.google.com/file/d/1tefgnZf0b5ulpwI2lMb9ly8m9PO9Pbfh/…
-
Asperi:我从 mac OS 压缩了两个项目 sim_backend_UI 和 mobile_sensor_API。您将需要使用您的... 目标 > 签名 > 团队和目标 > 构建设置 > 全部 > 打包 > 产品捆绑标识符来设置项目 ..因为我从中删除了我们的公司。
标签: ios objective-c swift xcode language-interoperability