目前,我已经使用 NativeScript 和 Typescript 涉足开发领域,但现在我遇到了一个一直困扰着我的问题。
我正在借助“nativescript-plugin-seed”开发一个插件,它使用 pod (AudioKit) 进行音频转换。我的问题是我应该如何将“AudioKit”模块导入插件以使用其功能,然后在应用程序中使用它们
我在 Swift 中包含了我在 Xcode 项目中测试的音频转换代码,以验证其正确操作,以及我认为应该导入模块以生成将与我的应用程序通信的方法的模板。
快速代码
import UIKit
import AudioKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let fileManager = FileManager.default
do {
let origin = Bundle.main.url(forResource: "IOS", withExtension: "mp4")
let documentDirectory = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:false)
let destination = documentDirectory.appendingPathComponent("test.wav")
var options = AKConverter.Options();
options.format = "wav";
options.sampleRate = 48000;
options.bitDepth = 16;
let converter = AKConverter(inputURL: origin!, outputURL: destination, options: options)
converter.start(completionHandler: { error in
if(error != nil){
print("ERROR")
}else{
print("CORRECT")
}
})
}
catch {
print(error)
}
}
插件代码 (my-plugin.ios.ts)
import { Common } from './audio-converter.common';
//I suppose the module should be declared here
export class AudioConverter extends Common {
// and used here
}
**已编辑
我已经使用了命令 HERE但从未创建打字文件。以同样的方式我阅读如果 pod 是用 Swift 编写的,我必须配置 pod 文件和 build.xcconfig,但是无论如何它都不起作用。我会评论我正在执行的步骤,以验证我没有做错什么。
- 使用 git clone 创建插件 https://github.com/NativeScript/nativescript-plugin-seed并配置插件名称......
添加pod文件
pod 'AudioKit', '~> 4.0' post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_SWIFT3_OBJC_INFERENCE'] = 'On' config.build_settings['SWIFT_VERSION'] = '4.0' end end end
向 build.xcconfig 添加标志
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
执行这些命令以在/src 中创建输入文件(-EDITED 为了创建输入文件,这些命令必须在/demo 中使用)
TNS_DEBUG_METADATA_PATH="$(pwd)/metadata" tns build ios [--for-device] [--release] TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios [--for-device] [--release]
在这一点上,我假设我必须在 typing carpet 中获取文件,但我没有获取它们
最佳答案
设置 POD 后,库中所有公开的 Objective C api 都可供您访问。如果您想为库使用 TypeScript Intellisense,则必须先生成类型。
Here您会找到有关生成打字的文档。生成后,您必须将它们导入到您的 reference.d.ts
中。
如果您还不熟悉将 Objective C 编码为 JS/TS,那么您可能想要开始 here .
关于javascript - 将 iOS 模块从 pod 导入 nativescript 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53841382/