javascript - 将 iOS 模块从 pod 导入 nativescript 插件

标签 javascript ios swift typescript nativescript

目前,我已经使用 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,但是无论如何它都不起作用。我会评论我正在执行的步骤,以验证我没有做错什么。

  1. 使用 git clone 创建插件 https://github.com/NativeScript/nativescript-plugin-seed并配置插件名称......
  2. 添加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
    
  3. 向 build.xcconfig 添加标志 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES

  4. 执行这些命令以在/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]
    
  5. 在这一点上,我假设我必须在 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/

相关文章:

JavaScript 无限滚动 + 延迟加载 - 如何确定 HTTP 请求的优先级(它正在占用可用连接)?

ios - 通过 Xcode import auto 提示的这条红线是什么

ios - 将键和值添加到 Firebase 中 JSON 树中的所有子节点

swift - Realm - 在 Azure 上同步数据的最佳方式

javascript - 图表 js 中带有注释插件和类别轴的垂直线?

javascript - Angular 指令不会触发 ngModel 中的更改事件

ios - 无法将 PrototypeCell 添加到 xib 文件中的 UITableView

objective-c - CGImageRef 属性保留或不保留

ios - iOS 框架内使用的图像未在测试应用程序上加载

javascript - wrappedComponentRef 未定义 - React Ant Design,表单组件