iOs5:从 URI 表示创建 NSManagedObject 时出现 NSInvalidArgumentException

发布于 2024-12-13 09:56:50 字数 637 浏览 0 评论 0原文

我刚刚安装了 iOs5,几乎所有的都出奇地流畅 - 但现在我遇到了一个奇怪的问题:

我的应用程序将 NSManagedObjects 的对象 ID 写入文本文件,然后再次读取它们并重新实例化相应的对象来自持久存储的对象。在更新之前它工作正常,现在当我调用

[persistentStoreCoordinator ManagedObjectIdForURIRepresentation:[NSURL URLWithString:objectIdString]]

时,我得到一个 NSInvalidArgumentException - 指定的 URI 不在正确的方案中

调用

谷歌搜索无效参数异常的具体原因根本没有提供任何信息,并且对象 id 正是对[[objectId 的 URIRepresentation]absoluteString]

返回。根据苹果文档,对 managedObjectIdForURIRepresentation 的调用甚至不应该引发 NSInvalidArgumentException,而只是返回 nil,以防出现问题......

I just installed iOs5, and almost all went surprisingly fluent - but now I have a weird problem:

My App writes Object Ids of NSManagedObjects to a text file, and then reads them again and re-instantiates the corresponding objects from the persistent store. It worked fine before the update, and now when I call

[persistentStoreCoordinator managedObjectIdForURIRepresentation:[NSURL URLWithString:objectIdString]]

I get an NSInvalidArgumentException - The specified URI is not in the proper scheme

Googling that specific reason for an invalid argument exception delivers nothing at all, and the object id is exactly what the call to

[[objectId URIRepresentation]absoluteString]

returns. And according to the apple documentation the call to managedObjectIdForURIRepresentation should not even raise an NSInvalidArgumentException, but just return nil in case something is wrong ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2024-12-20 09:56:50

好吧,我自己找到了。

对于有类似问题的任何人:主要问题不是 ManagedObjectIdForURIRepresentation 调用,而是传入的 objectIdString - 尽管 InvalidArgumentException 不应该由函数调用引发,恕我直言,因为文档中没有说明。

实际问题更奇怪:objectIdString 来自我通过使用调用应用程序的

(BOOL)application:(UIApplication*)application handleOpenURL:(NSURL 的 URL 方案获得的 URL *)url

函数。单击的 URL 方案条目具有正确的格式,例如

appname://x-coredata://objectid

但是:我在 中真正得到的内容handleOpenURL 函数是这样的:

appname://x-coredata//objectid

显然缺少一个重要的细节:x-coredata后面的冒号!!!这导致了崩溃......对我来说似乎是handleOpenURL 中的一个错误...

无论如何,现在的解决方法是查看该冒号是否丢失,然后添加它 - 然后一切正常。将向 Apple 提交错误报告。

Ok, found it myself.

For anyone with a similar problem: The main problem was not the managedObjectIdForURIRepresentation call, but the objectIdString that came in - although the InvalidArgumentException should not be thrown by the function call IMHO, as it's not stated in the docs.

The actual problem is even more strange: The objectIdString comes from an URL that I get by using a URL scheme that calls my application's

(BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url

function. The URL scheme entry that is clicked has the right format, like

appname://x-coredata://objectid

BUT: What I really do get in the handleOpenURL function is this:

appname://x-coredata//objectid

which is clearly missing an important detail: the colon after x-coredata!!! And that is causing the crash ... seems like a bug in handleOpenURL to me ...

Anyway, the workaround for now is to see whether this colon is missing, and then adding it - all works fine then. Going to file a bug report with Apple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文