使用IOS静态库问题创建NativeScript插件 [英] Create NativeScript Plugin using IOS Static Library issue

查看:123
本文介绍了使用IOS静态库问题创建NativeScript插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个静态库(已在Xcode中针对本机ios项目进行了测试,并且工作正常) 现在,我正在关注 https://github.com/NativeScript/nativescript-plugin-seed使用.a静态框架创建nativescript插件.

I have created .a static library (tested in Xcode for native ios project and Its working fine) Now I am following this https://github.com/NativeScript/nativescript-plugin-seed to create nativescript plugin using .a static framework.

插件结构

module.modulemap 文件是由我创建的,看起来像这样

module.modulemap file is created by me and it's look like this

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()方法.

Then in helloplugin.common.ts I am trying to access staticlibrary.sayHello() method.

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'.

我在做什么错了?

推荐答案

这只是TypeScript编译器错误,您必须为静态库生成类型(请参考

It's just the TypeScript compiler error, you have to generate typings for your static library (refer docs to know how) or just add this line at top of your file.

declare var staticlibrary: any

我看到您的代码段中确实有一个声明文件,如果要使用它,则必须将其包含在您的references.d.ts文件中.

I see that you do have a declaration file in your code snippet, if you want to use it you have to include it to your references.d.ts file.

这篇关于使用IOS静态库问题创建NativeScript插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆