简体   繁体   English

如何验证资产(在 flutter 插件中)在 iOS 中可用

[英]How to verify that an asset (in a flutter plugin) is available in iOS

I have an app written in flutter and with native bindings on android (java) and iOS (objective-c).我有一个用 flutter 编写的应用程序,并在 android (java) 和 iOS (objective-c) 上具有本机绑定。

The app is build as a flutter plugin for the native layer bindings and this is then wrapped into a flutter app for UI etc.该应用程序构建为用于本地层绑定的 flutter 插件,然后将其包装到用于 UI 等的 flutter 应用程序中。

The flutter plugin requires a binary dynamic library, but I struggle to get it to load on iOS. flutter 插件需要一个二进制动态库,但我很难让它加载到 iOS 上。 I am however unsure if this is because the library asset (eg mylib.dylib) is included in the app or if the code for finding it is broken.然而,我不确定这是否是因为库资产(例如 mylib.dylib)包含在应用程序中,或者查找它的代码是否损坏。

Is there a way to verify that the library is actually included in the app when building it for iOS?在为 iOS 构建库时,有没有办法验证该库是否实际包含在应用程序中? Maybe if there is a way to get it to list all assets with location so I can look through the list and verify that the location matches what I expect it to be.也许如果有办法让它列出所有带有位置的资产,这样我就可以查看列表并验证该位置是否符合我的预期。

I have added a line to my pubspec.yaml on the flutter plugin like我在 flutter 插件上的 pubspec.yaml 中添加了一行,例如

assets: - ios/Assets/mylib.dylib资产: - ios/Assets/mylib.dylib

The lib file is located in pluginroot/ios/Assets/ so I would expect that this is the right location. lib 文件位于 pluginroot/ios/Assets/ 所以我希望这是正确的位置。

In the Objective-C code I have used在我使用过的 Objective-C 代码中

NSString* key = [registrar lookupKeyForAsset:@"ios/Assets/mylib.dylib"];

NSString* path = [[NSBundle mainBundle] pathForResource:key ofType:nil];

but path is empty at this point.但此时路径为空。

The flutter plugin is not able to run on its own (i haven't extended the "example" app to exercise this part of the code), so only way for me to use this is by loading the flutter plugin into my UI flutter app and then see how it goes. flutter 插件无法自行运行(我没有扩展“示例”应用程序来练习这部分代码),所以我使用它的唯一方法是将 flutter 插件加载到我的 UI flutter 应用程序中然后看看情况如何。

Since the flutter plugin should already contain the asset, I would not expect the UI app to also have to add the asset to the pubspec - is this correct?由于 flutter 插件应该已经包含资产,我不希望 UI 应用程序也必须将资产添加到 pubspec - 这是正确的吗?

You must specify which package the image comes from.您必须指定图像来自哪个 package。

NSString *backImgKey = [registrar lookupKeyForAsset:@"images/ic_back.png" fromPackage:@"you_package_name"];
NSString *backImgPath = [[NSBundle mainBundle] pathForResource:backImgKey ofType:nil];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM