Search code examples
iossprite-kittvoscore-motion

Could not build Objective-C module CoreMotion error for tvOS target


I'm getting a couple of errors when creating my tvOS target from my Sprite Kit iOS game.

The first is: Could not build Objective-C module CoreMotion

Second: Umbrella header "CoreMotion.h" not found

enter image description here

In order to port the game, I've selected most of my files and assets from the iOS target and checked the TVOS target.

enter image description here

If I comment out all of the CoreMotion code, then the errors go away. I've searched Google and here to find an answer, but didn't find anything substantial.

Anyone know how to solve this?


Solution

  • The problem was the tvOS doesn't support CoreMotion.

    I had to use iOS specific code to make it work for all relevant code.

    Like so:

    #if os(iOS)
       import CoreMotion
    #endif
    

    You could also make tvOS specific code:

    #if os(iOS)
      let gameGain: CGFloat = 2.5
    #elseif os(tvOS) // tvOS
      let gameGain: CGFloat = 2.0
    #endif