How to extend iOS app to tvOS

后端 未结 9 1840
别跟我提以往
别跟我提以往 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
      

提交回复
热议问题