我正在构建一个将使用 MonoTouch (Xamarin.iOS) 和 Cordova (PhoneGap) 组合的应用程序。UI 将主要使用 Cordova 制作,我们的业务逻辑将主要使用 MonoTouch 编写。
我找到了描述这种情况的指南,所以我知道这是可能的,并且作者在他们的 monotouch-bindings 项目的分支中添加了一个 Cordova 绑定。
不幸的是,当我尝试使用绑定创建单视图项目时,我几乎立即开始遇到问题。我使用提供的 Cordova 库中的 make 文件为此构建了 dll,并ViewDidLoad
在我的测试应用程序的简单视图控制器中添加了方法MyViewController
。这是我的来源
public class MyViewController : UIViewController
{
private CDVViewController cdv;
public MyViewController()
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.Frame = UIScreen.MainScreen.Bounds;
View.BackgroundColor = UIColor.White;
View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
cdv = new CDVViewController();
RectangleF rect = new RectangleF (0, 0, 320, 480);
CDV.View.Frame = rect;
View.AddSubview(cdv.View);
}
}
当我构造 时CDVViewController
,我得到以下异常:
MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[__NSCFArray dictionaryWithLowercaseKeys]: unrecognized selector sent to instance 0xc892680
at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSend (intptr,intptr)
at CordovaIOS.CDVViewController..ctor () [0x00000] in <filename unknown>:0
at <Project_name>.MyViewController.ViewDidLoad () [0x00043] in /Users/jstarke/tmp/<Project_name>/MyViewController.cs:32
at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:126
at <Project_name>.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00031] in /Users/jstarke/tmp/<Project_name>/AppDelegate.cs:23
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at <Project_name>.Application.Main (System.String[] args) [0x00000] in /Users/jstarke/tmp/<Project_name>/Main.cs:17
到目前为止,我对这个问题的研究表明,这几乎可以肯定是一个具有约束力的问题。我对绑定还不太了解,但我正在努力学习,任何帮助或建议将不胜感激。重申一下,我正在使用的绑定,从这里找到:https ://github.com/sblom/monotouch-bindings/tree/master/Cordova/Binding