1

I am trying to add conditional code to prevent "Symbol not found" errors on an iOS 7 device when using an iOS 8 class, in this case UIBlurEffect:

dyld: Symbol not found: _OBJC_CLASS_$_UIBlurEffect

Even though the code within the conditional does not run (I do not see the "UIBlurEffect will be used!" log statement), I still get the error. If I comment the block out, it runs fine.

BOOL blurAvailable = NSClassFromString(@"UIBlurEffect") ? YES : NO;
if (blurAvailable)
  NSLog(@"UIBlurEffect available");
else
  NSLog(@"UIBlurEffect not available");

if (navBarBlurBool && blurAvailable)
{
  NSLog(@"UIBlurEffect will be used!");
    if (![viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG])
    {
        // Code works on iOS 7 if this block is commented out:

        [self storeOriginalNavBarImages];

        [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        self.navigationController.navigationBar.shadowImage = [UIImage new];
        UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
        CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
        blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height);
        blur.userInteractionEnabled = NO;
        blur.tag = BLUR_NAVBAR_TAG;
        [self.navigationController.navigationBar insertSubview:blur atIndex:0];
    }
}

I don't understand - I would assume that if blurAvailable is false then the offending code should not run and I should not get the "Symbol not found" runtime error.

I'm using iOS 9.2 SDK. Xcode 7.2. Deployment target is iOS 7.0.

Adamski
  • 3,585
  • 5
  • 42
  • 78

2 Answers2

0

Please make sure that blurAvailable is really NO on iOS 7.

Maybe the class is available on iOS 7 but not marked as such in the documentation. They might have introduced it in iOS 7 as a private class (just hiding it in the doc and headers).

Try testing another class marked as "unavailable on iOS 7" like UIVisualEffectView.

nverinaud
  • 1,270
  • 14
  • 25
  • Testing for `UIVisualEffectView` has the same result. And I have confirmed `blurAvailable` is really `NO` as I get the the log statement appearing "UIBlurEffect not available" – Adamski Jul 01 '16 at 09:31
  • Wait, so you see the log message "UIBlurEffect not available", but not "UIBlurEffect will be used!", so the code in that third if is not executed. Which line produces the error then? And is it really an error or just a warning? Remember that the compiler still does try to compile the code, so because you set the development target as 7.0 it will consider you using `UIBlurEffect` an error. I don't get something similar with XCode 7.3.1, but maybe that changed? – Gero Jul 01 '16 at 09:41
  • It does not say which line produced the error. But its definitely a runtime error. The project builds successfully. And its most certainly an error - crash on app startup. Are you suggesting updating Xcode might fix the issue? – Adamski Jul 01 '16 at 09:44
  • How is it possible for your first `if` to work but not the other one which test the same thing plus `navBarBlurBool` ? – nverinaud Jul 01 '16 at 09:58
  • @nverinaud: Both the `if` statements work in terms of showing the correct log statements. However, it seems that the presence of the code within the statement is somehow causing the "Symbol not found" error. – Adamski Jul 01 '16 at 10:16
  • 1
    It seems that you have a project configuration problem in Xcode so. This post may help you : http://stackoverflow.com/questions/24043532/dyld-symbol-not-found-nsurlauthenticationmethodclientcertificate-when-trying – nverinaud Jul 01 '16 at 11:17
0

From a comment in this question, the answer is to add UIKit as an Optional dependency in "Build Phases" -> "Link Binary with Libraries". I can now run the conditional iOS 8 code without errors on the iOS 7 device.

Community
  • 1
  • 1
Adamski
  • 3,585
  • 5
  • 42
  • 78