How to extend iOS app to tvOS
Asked Answered
T

9

66

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 should start a new project with it?

Update1: My question is: How to extend my existing project to support tvOS without building it from scratch?

Update2: Jess Bower point on Apple's website:

Empower customers to enjoy their favorite apps on both iOS and the new Apple TV with a single purchase by enabling universal purchase for your app on the App Store.

Which means that we need to create a new bundle on our existing project and enable "universal" purchase so it will count as one app on App Store.

Temperate answered 9/9, 2015 at 22:16 Comment(4)
The release notes say that (right now, at least) "you can not copy objects from an iOS storyboard and paste them into a tvOS one". Ouch!Arcuation
Worth noting that there is a new possible value for UIUserInterfaceIdiom, UIUserInterfaceIdiomTV.Felixfeliza
I have successfully whole views containing labels, subviews and images etc from an ios app storyboard to a tvOS app storyboard - it can be done. However I believe there will be limitations for a view that supports subviews like UISwitch, or UIDatePicker - these are not supported on tvOS. I believe adding a new target to an existing iOS app is the way forward.Libretto
It's not a universal app bundle. it's a universal PURCHASE. Meaning that you have 2 apps, an iOS app (which could be phone and pad universal bundle) and a tvOS app (which is a completely different build). Then they're just selling them together for one price as a "universal purchase".Servomotor
S
30

The tvOS SDK is based off of iOS, but is not interchangeable. Unlike when the first iPad was released, the new Apple TV will not be capable of running iOS apps.

The AppStore for the TV will only include apps built specifically for tvOS.

For any iOS developers looking to create apps for Apple TV, I'd recommend checking out the new documentation page: https://developer.apple.com/library/content/documentation/General/Conceptual/AppleTV_PG/index.html#//apple_ref/doc/uid/TP40015241-CH12-SW1

Specifically, check out the Inherited iOS Frameworks section to give you a sense of what will work out of the box from your existing iOS projects.

Sewerage answered 9/9, 2015 at 23:28 Comment(3)
Hi and thanks for your answer. Do you know what is all about TVML and Javascript? Is just another option to build the app? Because in Xcode I can see that is the same procedure like building apps for iOSTemperate
Client-server apps using JavaScript and TVML differ slightly from other apps. The main function of the Xcode app is to access a main JavaScript file and present pages created from TVML files onto the screen. So you have a choice if you would like to create an app like you do for iOS or an app based on TVMLJughead
You can also include swift files in both versions and subclass for differentiation.Barrera
O
21

In Xcode 7.1 (which introduces tvOS SDK) you can add a tvOS target as any other (File -> New -> Target... -> tvOS -> ...) and it supports both Objective-C and Swift, so yes - it's possible to share code between your iOS and tvOS app, you just need to check your source target membership and enable it on your tvOS target. To extend the purchases across iOS and tvOS app we should use Universal Purchases.

Oaks answered 10/9, 2015 at 12:10 Comment(7)
Yes I tried that. I was expecting something like iPad-iPhone with different storyboards. But if I build for tvOS so the app will have different ID from iOS and it would be a whole new app, not an extension. Same goes for Submitting to iTunesTemperate
for now create a separate target. You can put code that exists only in that target. I'm guessing more info on how an app can be universal is still forthcoming.Orelu
I gues we will be able to share the same bundle identifier on the tvOS targer, but as @JessBowers said - we will see...Oaks
ok just found more. It's Universal purchase: (not universal binary, so not the same bundle/deliverable): developer.apple.com/tvos "Empower customers to enjoy their favorite apps on both iOS and the new Apple TV with a single purchase by enabling universal purchase for your app on the App Store." So again, make a separate targetOrelu
I have even seen it before @JessBowers, but as always the interpretation of their simple sentences in the documentation is crucial :)Oaks
I believe this should be the correct answer - I have ported an app to tvOS already. I did it as a separate app, and there are a few inaccuracies in other answers. i COULD copy a view from a storyboard between the two apps. However, adding a new target is the correct way to go, and I will do this for my app.Libretto
You can use the same Universal Identifier for both your iOS apps and your TvOS app, and that means you get 1 single universal app, but still can upload and release the binaries independently.Wispy
A
18

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.
Allaallah answered 2/11, 2015 at 4:49 Comment(1)
Also the demobots app is a great resource to check againstAllaallah
D
17

I also believe that adding a new target for tvOS is the way to go, especially if you have lots of objective-c or swift code to share between projects.

For those instances where there might be some tvOS-unsupported types in your shared code, I have used these preprocessor symbols to provide alternate code snippets for tvOS:

#if TARGET_OS_IOS
// iOS-specific code
#elif TARGET_OS_TV
// tvOS-specific code
#endif
Dincolo answered 11/10, 2015 at 13:17 Comment(9)
Any idea when TARGET_OS_IOS was first defined in an iOS SDK?Oligochaete
+Danoli3: it's been there since the beginning, I think. It used to only be defined for iOS builds, but recently (since iOS 8 I think) it's always defined, and is either set to 0 (for Mac, Watch or tvOS) or 1 (for iOS), so you must not use #ifdef to check it. Always use #if as above.Dincolo
I tried 8.1 SDK with travis and the pre-processor was skipping past it. Example: travis-ci.org/openframeworks/openFrameworks/jobs/87396739 Where #if TARGET_OS_IOS const string appDelegateName = "ofxiOSAppDelegate"; #endif was failing. To be clear this was working perfectly fine under Xcode 7.0 and Xcode 7.1 (tvOS defined).Oligochaete
I made a table of these macro values; hopefully it will help someone else: gist.github.com/jtbandes/cd8ee0cf139ae4411b41Teplica
To be sure for travis, you can write #if !defined(TARGET_OS_IOS) || TARGET_OS_IOS. But it will detect OS X as iOS on old Xcode.Lactoprotein
adding existing files in iphone target in watchapp resources gives me duplicate files being used error(like duplication of app delegate class).Pilcomayo
@jayantrawat You must keep some files for each target separate. Common code is ok to share, as long as it has the above sections to accommodate differences in platform requirements, but app delegates must always be unique to the target.Dincolo
@simon Tilson should i bring out view controllers which are having common code from my ios app target resources & keep it outside so that both tvOS & iOS app can use it coz when i import those files in tvOS app delegate class , i am getting duplicate class being used error?Pilcomayo
@jayantrawat Common MVC practise would suggest you only put minimal code in your view controllers, and leave the heavy work to helper classes which can be shared without platform difference issues. That way you only have minimal view controllers for each platform and less code to duplicate.Dincolo
H
10

Just to list out some limitations and challenges:
1. There is no persistent local storage for apps on Apple TV. Data must be stored on iCloud.

2. The maximum size of an Apple TV app is limited to 200MB. On-demand resources (app contents that are hosted on the App Store) should be used. Benefits are smaller app size and lazy loading of app resources.

3. The UI is drastically different. Human Interface Guidelines must be followed as per the doc.

4. Creating a Client-Server App using JavaScript and TVML framework.

5. Controlling the UI touch focus. UIFocusEnvironment controls focus-related behavior for a branch of the view hierarchy. UIViewController conforms to UIFocusEnvironment protocol.

6. Creating Parallax Artwork You have to create a LSR image with Xcode and then use terminal to create a LCR image. A UIImage object can display a LCR image correctly.

Hyperthyroidism answered 10/9, 2015 at 15:0 Comment(1)
This is not entirely accurate. Point 1 is not true. Point 4 it's just an option, you can use tvOS, you don't have to use TVML. Point 6, also an option. And, how is this an answer to the question ?Sewole
K
9
  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
    
Kenlay answered 3/2, 2016 at 21:23 Comment(1)
if i do steps 1 & 2 two separate targets are created . what is the purpose of doing so?Pilcomayo
O
5

+Simon-Tillson answer is correct, however I had some backwards compatibility issues with iOS 8.1 and below SDK's where TARGET_OS_IOS was not defined (for older Xcode versions)

The following code fixes that and works the same for iOS 9.0/9.1 SDK + and previous 8.1 and less SDKS.

#if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV)
// iOS-specific code
#elif TARGET_OS_TV
// tvOS-specific code
#endif
Oligochaete answered 28/10, 2015 at 8:4 Comment(0)
S
2

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.

Surfperch answered 21/10, 2015 at 7:56 Comment(1)
did you ever open-source the project?Chlores
G
0

Don't forget to change the Base SDK into TVos 9.x in the build settings. It's necessary for the Tv simulator to show up

Grimsley answered 1/6, 2016 at 14:8 Comment(1)
This would be better left as a comment rather than a separate answer.Needleful

© 2022 - 2024 — McMap. All rights reserved.