How to extend iOS app to tvOS

后端 未结 9 1770
别跟我提以往
别跟我提以往 2020-12-12 14:55

I have an iOS app that I need to extend to tvOS. All the information that I found are explaining how to start from scratch! Is there any way to extend my app to tvOS or I sh

相关标签:
9条回答
  • 2020-12-12 15:39
    1. A new target has to be added for tvOS. There are two ways to do that

      • Add a new target through File > New > File...> tvOS Target.
      • Duplicate an existing iOS target and change TARGETED_DEVICE_FAMILY to 3 and "Supported Platforms" to tvOS in "Build Settings"
    2. Pods need to be added to the tvOS target using pod install. There could be a different list of pods that you can/want to use in tvOS. Pods for different targets can be separated in Podfile using:

      target 'iOS TARGET NAME' do
      pod 'podname', :git => 'https://github.com/name.git'
      end
      
      target 'tvOS TARGET NAME' do
      pod 'podname', :git => 'https://github.com/name.git'
      end
      
    3. Most Pods at the moment do not support tvOS. For those Pods, here are the steps to make them work in your project:

      • Clone the git repo on your local disk
      • If a version of the pod is being used in another target (iOS target), change the name, otherwise CocoaPods will complain: e.g. RestKit --> RestKitTV and use :path In Podfile to point to the location of the cloned repo:

        pod 'RestKitTV', :path => 'Other/RestKitTV'
        
      • Update the podspec file in the cloned repo:

        • Modify the name to be compatible with the new name
        • Change the platform to tvOS or add tvOS to the list of supported platforms

           Pod::Spec.new do |s|
           ..
           s.platform = :tvos
           ..
           end
          

          OR

           Pod::Spec.new do |s|
           ..
           s.tvos.deployment_target = '9.0'
           s.tvos.exclude_files = 'framework/Source/Mac', ....
           s.tvos.frameworks   = ['OpenGLES', 'CoreMedia', 'QuartzCore']
           ..
           end
          
    4. Add files to the target:

      • Add source code (.m files) to "Compile Sources" of "Build Phases" for the target
      • Add images to "Copy Bundle Resources"
      • Add frameworks to "Link Binary with Libraries". Note that not all frameworks are compatible with tvOS
    5. Use TARGET_OS_TV and TARGET_OS_IOS macros to separate tvOS non-compatible code

      #if !TARGET_OS_TV
          *iOS only code*
      #else
          *tvOS only code*
      #end
      
    0 讨论(0)
  • 2020-12-12 15:40

    Took me a little while to find all the things needed to change but this list should cover it.

    1. click iOS target and duplicate
    2. change base sdk of new tvOS target to tvOS latest
    3. make copy of info.plist and have tvOS point to that one
    4. make all the tvOS icons and launch images
    5. set TARGETED_DEVICE_FAMILY to 3 for the tvOS build settings
    6. add any new tvOS specific versions of code e.g. without shouldAutorotate, prefersStatusBarHidden etc.
    0 讨论(0)
  • 2020-12-12 15:41

    In case of my project, I simply added a new target to the existing iOS project, and modified some code appropriately (using #if os(tvOS/iOS) in a few areas). I am now able to run the same app either on iOS devices or Apple TV.

    The only framework missing in tvOS was WebKit (which was necessary to render rich text), and I needed to come up with an alternative mechanism.

    I am going to open source this project soon (before the end of October), so that other people can take a look.

    0 讨论(0)
提交回复
热议问题