1

ZBarの MonoTouch バインディングが動作していますが、NSDictionary のキーとして使用するために Obj-C ライブラリが定義する定数 NSString を公開する際に問題があります。

ZBarReaderController.h 内:

extern NSString* const ZBarReaderControllerResults;  

ここに記載されているように、実際の MonoTouch バインディングを介して最初に試しました。

[Static]
interface ZBarSDK
{
    [Field ("ZBarReaderControllerResults")]
    NSString BarcodeResultsKey { get; }
}

これを含むプロジェクトをビルドしようとすると、btouch から次のエラーが発生しました。

未処理の例外: System.ArgumentOutOfRangeException: 引数が範囲外です。
パラメータ名:
System.String.Substring の startIndex (Int32 startIndex) [0x00000] in :0
at Generator.Generate (System.Type type) [0x00000] in :0
at Generator.Go () [0x00000] in :0
at BindingTouch .Main (System.String[] args) [0x00000] in :0
[エラー] 致命的な未処理の例外: System.ArgumentOutOfRangeException: 引数が範囲外です。
パラメータ名: startIndex
at System.String.Substring (Int32 startIndex) [0x00000] in :0
at Generator.Generate (System.Type type) [0x00000] in :0
at Generator.Go () [0x00000] in :0
BindingTouch.Main (System.String [] args) [0x00000] で:0

次に、 this other SO answerで提案されているように、手動でコードを呼び出そうとしました。

public static NSString BarcodeResultsKey
{
    get
    {
        var libHandle = Dlfcn.dlopen("libzbar.a",0);
        // I also tried this with "__Internal", rather than "libzbar.a"
        return Dlfcn.GetStringConstant(libHandle, "ZBarReaderControllerResults");
    }
}

正常にビルドおよび実行されますが、空の文字列が返されるだけです ( Dlfcn.GetStringConstantドキュメントと同様に、リンクに失敗した場合に実行されます)。

それで、他の誰かがサードパーティの Obj-C ライブラリから const 文字列にアクセスしましたか?

4

1 に答える 1

2

ジェネレーター には、名前空間を で開始する必要があるバインディングbtouchに対して (5.2.11 より前に) 制限がありました。[Field]MonoTouch.

この問題の簡単な回避策は、名前空間の名前を から に変更するZBarことです。これMonoTouch.ZBarにより、バインディング定義が正しくビルドされます。

iOS アプリケーションは、アプリケーションに含まれるライブラリの静的ライブラリ (.a) とリンクする必要があるため、ドキュメント"__Internal"で説明されているように、バインディングでライブラリ名を指定する必要もあります。

[Static]
interface ZBarSDK {
    [Field ("ZBarReaderControllerResults", "__Internal")]
    NSString BarcodeResultsKey { get; }
}

また、(生成されたコードで) コンパイルの問題があり、ライブラリを手動で調整する必要がありました (つまりnull、メイン アプリ内でリンクされているため、ライブラリ名の代わりに使用できます)。これは、MonoTouch 5.2.11 リリースでも修正されています。

回避策 (または MonoTouch 5.2.11) と変更により、バインディング内__Internalで使用できるようになります。[Field]

于 2012-04-09T13:16:23.133 に答える