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

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

问题描述

我创建了 .a 静态库(在 Xcode 中针对原生 ios 项目进行了测试,并且工作正常)现在我正在关注这个

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

module libstaticlibrary {伞头staticlibrary.h"出口 *}

staticlibrary.h

#import @interface 静态库:NSObject+ (NSString *)sayHello;@结尾

libstaticlibrary.d.ts 也是我创建的

declare class staticlibrary extends NSObject {静态 sayHello():string;}

然后在 helloplugin.common.ts 我试图访问 staticlibrary.sayHello() 方法.

导出类 Utils {公共静态 SUCCESS_MSG(): 字符串 {//let msg = `你的插件正在运行 ${app.android ?'安卓':'iOS'}.`;让 msg = staticlibrary.sayHello();setTimeout(() => {dialogs.alert(`${msg} 真的.它真的很有效:)`).then(() => console.log(`Dialog closed.`));}, 2000);回消息;}

我收到以下错误.

node_modules/nativescript-helloplugin/helloplugin.common.ts(21,15): 错误 TS2304: 找不到名称staticlibrary".

我在这里做错了什么?

解决方案

这只是 TypeScript 编译器错误,您必须为静态库生成类型(请参阅 docs 以了解如何)或仅在文件顶部添加此行.

声明 var staticlibrary: any

我看到你的代码片段中有一个声明文件,如果你想使用它,你必须将它包含到你的 references.d.ts 文件中.

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.

Plugin structure

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 also created by me

declare class staticlibrary extends NSObject {

    static sayHello():string;

}

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;
  }

I am getting following error.

node_modules/nativescript-helloplugin/helloplugin.common.ts(21,15): error TS2304: Cannot find name 'staticlibrary'.

What is I am doing wrong here?

解决方案

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

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天全站免登陆