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
A new target has to be added for tvOS. There are two ways to do that
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
Most Pods at the moment do not support tvOS. For those Pods, here are the steps to make them work in your project:
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:
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
Add files to the target:
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
Took me a little while to find all the things needed to change but this list should cover it.
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.