0

I'm getting the following message in my users' crash logs:

Dyld Error Message: Symbol not found: _OBJC_CLASS_$_NSMetadataQuery

So I understand the solution is that I should be making the Foundation framework "Optional". But what's bizzare to me is this crash only happens on some iOS4 devices, but not others, and it doesn't crash in the 4.3 simulator either. It's only happening on iPads (running iOS4) specifically, but even then, it's only on some of them. Can someone explain why that might be?

If it's a bug with linking frameworks, it should crash on all iOS4 devices (or at least all iPads), right?

Z S
  • 7,039
  • 12
  • 53
  • 105

2 Answers2

1

NSMetadataQuery is available on iOS >= 5.0, which I assume you know since you are talking about weak-linking the framework.

First off, you probably don't need to do that any more.

Since this is occurring at run-time, and non-reproducibly, it sounds like an inconsistency in your logic. Is there anywhere you use NSMetadataQuery without first ensuring the class exists? Your code should be wrapped in an idiom like:

if ([NSMetadataQuery class] != nil) {
    // Use the class
}
Conrad Shultz
  • 8,748
  • 2
  • 31
  • 33
  • I'm doing a couple of things: declaring a NSMetadataQuery object (that is unused) as an ivar in the AppDelegate. Also, checking for iOS4 with this: BOOL isIOS4 = ([[NSFileManager defaultManager] respondsToSelector:@selector(URLForUbiquityContainerIdentifier:)])? FALSE: TRUE; – Z S Feb 12 '12 at 01:54
  • Alright, this really isn't how you want to be testing for availability at run-time; use the mechanism I describe above (and detailed in the supplied link). I'm more interested in the ivar... is it on a class that is selectively loaded only in iOS 5? – Conrad Shultz Feb 12 '12 at 09:02
  • Is checking "respondsToSelector" worse than checking for class availability? The ivar thing is a red-herring I think; I was testing some things with it, and it's unloaded, even in iOS5. But the ivar has been there in production for a couple of releases without giving any problems. The respondsToSelector check was new. – Z S Feb 12 '12 at 20:23
0

I had this exact error. It wasn't a case of logic as it was crashing before the App Delegate was even called and my usage of NSMetadataQuery was much later in the life cycle than that.

It turns out that weak linking the Foundation framework was required.

Daniel Wood
  • 4,487
  • 3
  • 38
  • 36