1

バインディングに関する別の質問 ( Issues with Bindings: Calling base method on binding class calls override method. Leads to infinite recursion ) に関連する別の質問があります。現時点でわかっている情報。

MonoTouch 内で作業しているプロジェクトで Cordova を使用しようとしています。Cordova のバインディングに取り組んでいます。

Cordova 2.4.0 クラスのバインディングは次のとおりです ( https://github.com/apache/cordova-ios/tree/2.4.0/CordovaLib/Classesから入手できます): (これは完全なバインディングではなく、これまでに必要なピース

interface CDVScreenOrientationDelegate {
    [Export ("supportedInterfaceOrientations")]
    uint SupportedInterfaceOrientations ();

    [Export ("shouldAutorotateToInterfaceOrientation:")]
    bool ShouldAutoRotateToInterfaceOrientation (UIInterfaceOrientation interfaceOrientation);

    [Export ("shouldAutorotate")]
    bool ShouldAutoRotate ();
}

[BaseType (typeof (UIViewController))]
interface CDVViewController : CDVScreenOrientationDelegate {
    [Export ("webView")]
    UIWebView WebView { get; set; }

    [Export ("pluginObjects")]
    NSMutableDictionary PluginObjects { get; }

    [Export ("pluginsMap")]
    NSDictionary PluginsMap { get; }

    [Export ("settings")]
    NSDictionary Settings { get; }

    [Export ("whitelist")]
    CDVWhitelist Whitelist { get; }

    [Export ("loadFromString")]
    bool LoadFromString { get; }

    [Export ("useSplashScreen")]
    bool UseSplashScreen { get; set; }

    [Export ("activityView")]
    UIActivityIndicatorView ActivityView { get; }

    [Export ("imageView")]
    UIImageView ImageView { get; }

    [Export ("wwwFolderName")]
    string WwwFolderName { get; set; }

    [Export ("startPage")]
    string StartPage { get; set; }

    [Export ("commandQueue")]
    NSObject CommandQueue { get; set; }

    [Export ("commandDelegate")]
    NSObject CommandDelegate { get; set; }

    [Export ("userAgent")]
    string UserAgent { get; }

    [Export ("printMultitaskingInfo")]
    void PrintMultitaskingInfo ();

    [Export ("createGapView")]
    void CreateGapView ();

    [Export ("newCordovaViewWithFrame:")]
    UIWebView NewCordovaView(RectangleF bounds);

    [Export ("javascriptAlert:")]
    void JavascriptAlert (string text);

    [Export ("appURLScheme")]
    string AppUrlScheme ();

    [Export ("parseInterfaceOrientations:")]
    NSArray ParseInterfaceOrientations (NSArray orientations);

    [Export ("supportsOrientation:")]
    bool SupportsOrientation (UIInterfaceOrientation orientation);

    [Export ("getCommandInstance:")]
    NSObject GetCommandInstance (string pluginName);

    [Export ("registerPlugin:withClassName:")]
    void RegisterPluginWithClassName (CDVPlugin plugin, string className);

    [Export ("URLisAllowed:")]
    bool UrlIsAllowed (NSUrl url);

    [Static] [Export ("getBundlePlist:")]
    NSDictionary GetBundlePlist (string plistName);

    [Static] [Export ("applicationDocumentsDirectory")]
    string ApplicationDocumentsDirectory ();

    // The following methods and properties come from UIWebViewDelegate, but we can't do multiple inheritance
    //[Export ("webView:shouldStartLoadWithRequest:navigationType:")]
    //bool ShouldStartLoad (UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType);
}

[BaseType (typeof(NSObject))]
interface CDVWhitelist {
    [Export ("whitelist")]
    NSArray Whitelist { get; }

    [Export ("expandedWhitelist")]
    NSArray ExpandedWhitelist { get; }

    [Export ("allowAll")]
    bool AllowAll { get; }

    [Export ("initWithArray:")]
    IntPtr Constructor (NSArray array);

    [Export ("URLIsAllowed:")]
    bool UrlIsAllowed (NSUrl url);

    [Export ("schemeIsAllowed:")]
    bool SchemeIsAllowed (string scheme);

    [Export ("errorStringForURL:")]
    string ErrorStringForUrl (NSUrl url);
}

[BaseType (typeof(NSObject))]
interface CDVPlugin {
    [Export ("webView")]
    UIWebView WebView { get; set; }

    [Export ("viewController")]
    UIViewController ViewController { get; set; }

    [Export ("commandDelegate")]
    NSObject CommandDelegate { get; set; }

    [Export ("hasPendingOperation")]
    bool HasPendingOperation { get; }

    [Export ("initWithWebView:")]
    CDVPlugin InitWithWebView (UIWebView theWebView);

    [Export ("handleOpenURL:")]
    void HandleOpenUrl (NSNotification notification);

    [Export ("onAppTerminate")]
    void OnAppTerminate ();

    [Export ("onMemoryWarning")]
    void OnMemoryWarning ();

    [Export ("onReset")]
    void OnReset ();

    [Export ("appDelegate")]
    NSObject AppDelegate ();
}

これはMonotouch Binding Syntax For Protocolsの miguel.de.icaza のプロトコルを使用しています。これには、CDVViewController でも採用されている UIWebViewDelegate がありません。

@interface CDVViewController : UIViewController <UIWebViewDelegate, CDVScreenOrientationDelegate>{
    @protected
    CDVCommandDelegateImpl* _commandDelegate;
    @protected
    CDVCommandQueue* _commandQueue; 
    NSString* _userAgent;
}

あるいは、Rolf Bjarne Kvinge がhttp://monotouch.2284126.n4.nabble.com/Objective-C-protocol-binding-method-not-invoked-td4105828.htmlで Adopts 構文を推奨していることがわかりました。残念なことに、バインディングを作成しようとすると、 に準拠できないと文句を言うので、これを機能させることができませんでしSystem.TypeString。それは別の問題ですが。

CDVViewController をサブクラス化しようとすると、別の問題が発生します。特にViewDidLoadが呼び出された後、システムは私のサブクラスを呼び出しますShouldAutoRotateToInterfaceOrientation

これを確認するために、次のことを行いました。

public class WebViewController : CDVViewController
{
    public override bool ShouldAutoRotateToInterfaceOrientation (MonoTouch.UIKit.UIInterfaceOrientation interfaceOrientation)
    {
        Console.WriteLine ("Enter ShouldAutoRotateToInterfaceOrientation");
        var output = base.ShouldAutoRotateToInterfaceOrientation;
        Console.WriteLine ("Leave ShouldAutoRotateToInterfaceOrientation");
        return output;
    }
}

内にブレークポイントを置き、ShouldAutoRotateToInterfaceOrientationメソッドに沿って進み、 に到達すると、base.ShouldAutoRotateToInterfaceOrientationこのメソッドの先頭にホップバックするだけで、コール スタックに が追加されましCordova.CDVViewController.ShouldAutoRotateToInterfaceOrientationたが、このメソッドのソース コードを見ると (ここで入手可能)、それ自体またはサブクラスの実装を呼び出そうとすることはありません。代わりに内部的に呼び出しsupportsOrientation:、配列をチェックして、この向きがサポートされているかどうかを確認します。

supportsOrientation:とにかく最後にそれが呼び出されることを知って、私ShouldAutoRotateToInterfaceOrientationもそれを呼び出してみましたが、代わりにそのメソッドで奇妙なコールバック動作が発生します。

CDVViewController直接インスタンス化すると、すべてが期待どおりに機能するように見えますが、プロジェクトのいくつかのメソッドをオーバーライドする必要があります。を拡張するCDVViewControllerと、この動作が発生し始めます。

私はこれにかなり混乱しており、何が間違っているのか理解できないので、どんな助けも大歓迎です。

更新 #1 Rolf の要求に基づいて、生成されたクラスを以下に示します。これがあなたが探していたものであることを願っています。スペース上の理由から、ここに Gist として追加しますhttps://gist.github.com/innopal/5288047

4

1 に答える 1