【问题标题】:How to use swift library in NativeScript?如何在 NativeScript 中使用 swift 库?
【发布时间】:2015-10-29 15:01:35
【问题描述】:

我正在尝试在 NativeScript 中使用 this ios-charts library。这个库是用 Swift 而不是 Objective-C 编写的。我可以使用它吗?我曾尝试使用它,但它给了我一个错误。我已在以下步骤中使用它:

为此,我在我的 nativescript 项目中添加了库

tns library add ios 'library_path'

库被添加。然后我使用

为 ios 平台准备项目
tns prepare ios

为了测试库是否添加成功,我在Xcode中构建项目,它构建成功,但在运行时出现以下错误。

 dyld: Library not loaded: @rpath/libswiftCore.dylib
 Referenced from: /Users/UserNameHere/Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphonesimulator/Charts.framework/Charts
 Reason: image not found

当我将Embedded content contains swift code 设置为YES 时,我摆脱了这个错误。但是现在当我尝试以

身份访问库时
var charts = new Charts();

它给出如下参考错误:

ReferenceError: Can't find variable: Charts

我已经尝试过的:

我尝试使用以下方法访问图表:

1. var charts = new Charts.Swift();
2. var charts = new Charts.Charts();
3. var charts = new Charts-Swift();
4. var charts = new Charts.LineChartView();
5. var charts = require("Charts");
6. var charts = require("../../lib/Charts.framwork");
7. var charts = require("Charts.framework");

所有这些方法都给出相同的确切错误。

参考文献

我按照这些链接来开发我的项目

Using-native-libraries-in-your-nativescript-apps

在可可豆荚中使用原生库:docs.nativescript.org/runtimes/ios/native-libs/CocoaPods

即使我用 Cocoa Pods 尝试这个,它仍然会给出同样的错误。

如果有人试过这个,请告诉我。

【问题讨论】:

标签: ios swift nativescript


【解决方案1】:

您可以检查例如我的对话框插件: https://github.com/enchev/nativescript-dialog

我正在使用 Swift 库 SDCAlertView,您可以在 pod 和 xconfig 文件中找到有关如何设置它的更多信息: https://github.com/enchev/nativescript-dialog/tree/master/platforms/ios

所有类最有可能在全局上下文中可用。例如:

var chart = new BarChartView(); 

【讨论】:

    猜你喜欢
    • 2020-05-13
    • 2018-08-19
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 2020-01-17
    • 1970-01-01
    • 2019-11-12
    相关资源
    最近更新 更多