tvOS Framework Target bug
There be bugs here
Getting past the simple project stage with your tvOS app?
Maybe you’re putting reusable/common code in frameworks and then linking to them from your tv project.
What could go wrong?
Introduction
So I created an Xcode workspace. Then under Framework & Library, I created and added a TV Framework project. I created a class in the framework then built it.
Then I created a TV app. In this project I set “Linked Frameworks and Libraries” to use my framework. I also added the framework to “Embedded Binaries”. If you don’t do this, you will get a link failure when you run on the actual device.
In the app I imported the framework and referenced the (public of course) framework class.
It works!
Groovy.
Here’s the Project Navigator. Total grooviosity.
The Problem
So, what am I complaining about?
I have another pile of code that works on iOS and Cocoa. In this project (a “Cocoa Touch Framework”, I simply have two targets – one for iOS and Cocoa. In the code I use #if os(iOS) or os(OSX). You can check to tvOS too.
Like this:
1 2 3 4 5 |
#if os(iOS) || os(tvOS) import UIKit #elseif os(OSX) import Cocoa #endif |
I’m sure you’ve done that too. That works just fine.
So, what’s the problem?
I’m getting there.
In your multi-target project, add a TV framework target. If it works for Cocoa and iOS, it should work for tvOS too, right?
Well, sort of. It works in the simulator but not on the device.
Here is the same setup as above in the app.
This is what the Project Navigator looks like:
Lots of red.
Let’s see what we get when you select the framework in the app.
Huh.
That’s not where it should be. If you look at the other framework, it’s in the Derived Data directory. Actually, that’s where it is (i.e. when I look in the derived data directory, it’s there), but Xcode thinks it’s in the project directory. (btw., the Embedded Binaries section shows the same wrong path)
Would you know how to fix this?
Summary
TV framework targets added to a project don’t link correctly in your app when run on the device.
Resources