可能的捆绑包问题 - 无法使用 nil 模型创建 NSPersistentStoreCoordinator
Posted
技术标签:
【中文标题】可能的捆绑包问题 - 无法使用 nil 模型创建 NSPersistentStoreCoordinator【英文标题】:Possible bundle problems - Cannot create an NSPersistentStoreCoordinator with a nil model 【发布时间】:2012-06-06 15:02:51 【问题描述】:我想将Aviary SDK Objective-C 库集成到 Monotouch 项目中。我为此使用“Monotouch Binding Project”模板。 我已经构建了DLL(感谢聪明人!)该项目已编译并在模拟器上运行。
但是我无法显示主 Aviary 视图和以下代码
this.afPhotoEditor = new AFPhotoEditorController(UIImage.FromFile("Images/site.jpg"));
AFDelegate afDelegate = new AFDelegate(this);
this.afPhotoEditor.Delegate = afDelegate;
this.PresentModalViewController(this.afPhotoEditor, true);
返回错误:
Unhandled Exception: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Cannot create an NSPersistentStoreCoordinator with a nil model
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr_bool (intptr,intptr,intptr,bool)
at MonoTouch.UIKit.UIViewController.PresentModalViewController (MonoTouch.UIKit.UIViewController modalViewController, Boolean animated) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIViewController.g.cs:261
at TestAviary.FirstViewController.<ViewDidLoad>m__0 (System.Object , System.EventArgs ) [0x00028] in /Users/mahmood1/Projects/AviaryBinding/TestAviary/FirstViewController.cs:61
at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:30
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) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at TestAviary.Application.Main (System.String[] args) [0x00000] in /Users/mahmood1/Projects/AviaryBinding/TestAviary/Main.cs:17
[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Cannot create an NSPersistentStoreCoordinator with a nil model
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSendSuper_IntPtr_bool (intptr,intptr,intptr,bool)
at MonoTouch.UIKit.UIViewController.PresentModalViewController (MonoTouch.UIKit.UIViewController modalViewController, Boolean animated) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIViewController.g.cs:261
at TestAviary.FirstViewController.<ViewDidLoad>m__0 (System.Object , System.EventArgs ) [0x00028] in /Users/mahmood1/Projects/AviaryBinding/TestAviary/FirstViewController.cs:61
at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:30
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) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at TestAviary.Application.Main (System.String[] args) [0x00000] in /Users/mahmood1/Projects/AviaryBinding/TestAviary/Main.cs:17
似乎此错误(无法使用 nil 模型创建 NSPersistentStoreCoordinator)与 Aviary SDK 需要添加的资源包相关联。
来自Aviary ios Setup Guide:
4. Copy resources Make sure AviarySDKResources.bundle is included in your target's "Copy Bundle Resources" build phase.
所以我通过 MonoDevelop 中的“添加现有文件夹..”菜单项添加了这个包。
Sources are placed here >>>http://www.axifile.com/en/71EC96914A
它包括 2 个项目:
AviaryBinding(MonoTouch 绑定项目) TestAviary谢谢!
【问题讨论】:
只是一个想法,您是否尝试过打开捆绑包(我认为它是“显示内容”,我现在在 Windows 上)并取出其中的所有资源?您可以将它们全部添加到 MonoDevelop 中的项目中。 感谢您的建议。是的,捆绑打开,我可以从中获取所有文件。但我尝试了很多组合 - 没有运气。我不知道什么会导致这个错误。也许 Aviary iOS 无法与 MonoTouch 集成。是否可以?或者 MonoTouch 可以绑定任何 ObjC 库? Shturman,你能和大家分享你(现在正在工作的)解决方案吗? 有人为新的 3.0 版本创建绑定吗?鉴于新的应用商店规则,我们必须让它进入商店。 在:github.com/theonlylawislove/MonoTouch.Aviary 找到 3.0 绑定,谢谢! 【参考方案1】:每Jonathan.Peppers评论:
使用Build Action
或Content
将大多数此类文件添加到您的项目将解决该问题。
【讨论】:
在此处查看我的绑定以获得有效的解决方案。 github.com/theonlylawislove/MonoTouch.Aviary以上是关于可能的捆绑包问题 - 无法使用 nil 模型创建 NSPersistentStoreCoordinator的主要内容,如果未能解决你的问题,请参考以下文章