我已经创建了.a静态库(在Xcode中测试本机ios项目并且它工作正常)现在我正在关注这个https://github.com/NativeScript/nativescript-plugin-seed使用.a静态框架创建nativescript插件 .
插件结构
module.modulemap 文件是由我创建的,它看起来像这样
module libstaticlibrary {
umbrella header "staticlibrary.h"
export *
}
staticlibrary.h
#import <Foundation/Foundation.h>
@interface staticlibrary : NSObject
+ (NSString *)sayHello;
@end
libstaticlibrary.d.ts 也是由我创造的
declare class staticlibrary extends NSObject {
static sayHello():string;
}
然后在 helloplugin.common.ts 我试图访问 staticlibrary.sayHello() 方法 .
export class Utils {
public static SUCCESS_MSG(): string {
// let msg = `Your plugin is working on ${app.android ? 'Android' : 'iOS'}.`;
let msg = staticlibrary.sayHello();
setTimeout(() => {
dialogs.alert(`${msg} For real. It's really working :)`).then(() => console.log(`Dialog closed.`));
}, 2000);
return msg;
}
我收到了以下错误 .
node_modules/nativescript-helloplugin/helloplugin.common.ts(21,15): error TS2304: Cannot find name 'staticlibrary'.
我在这做错了什么?
1 回答
这只是TypeScript编译器错误,您必须为静态库生成输入(请参阅docs以了解如何)或者只是在文件顶部添加此行 .
declare var staticlibrary: any
我看到你的代码片段中有一个声明文件,如果你想使用它,你必须将它包含在你的
references.d.ts
文件中 .