Skip to content

Commit

Permalink
fixed issue with runIOS not being able to launch tvOS app
Browse files Browse the repository at this point in the history
Summary:
Yes.

Yes

Environment:
OS: MacOS X 10.12.6 (16G29)
Node: 8.9.4
Yarn: N/A
npm: 5.4.2
Watchman: Not Found
Xcode: 9.2 (9C40b)
Android Studio: N/A

[CLI iOS runIOS] When using `react-native-cli` to try to launch the tvOS scheme the user get's an error because the current implementation for launching simulators ignores any simulator/device who's name does not start with `iOS`

StackOverflow issue also found here :  https://stackoverflow.com/questions/48069690/how-to-select-project-to-run-tvos-version-with-npm-start

Actual command line steps
```
$npm i -g react-native-cli
...
$react-native init CoolProject
...
$cd CoolProject/
$react-native run-ios --simulator "Apple TV"  --scheme "CoolProject-tvOS"

Scanning folders for symlinks in /Users/jjiron/CoolProject/node_modules (7ms)
Found Xcode project CoolProject.xcodeproj
CoreData: annotation:  Failed to load optimized model at path '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPackaging.framework/Versions/A/Resources/XRPackageModel.momd/XRPackageModel 9.0.omo'

Could not find Apple TV simulator
```

The cli tool should launch the tvOS application on the simulator.

The user get's an error message saying "Could not find Apple TV simulator"

Don't ignore appletv simulators when looking for simulators to launch. Also use the correct application build when selecting which app to launch on the simulator/device.

Added automated test for `findMatchingSimulator.js` to allow tvOS simulators

[react-native-cli] Fixed issue where you cannot launch tvOS app on Apple TV simulator
Closes #17660

Differential Revision: D6806327

Pulled By: hramos

fbshipit-source-id: 1a4f37058f3c5d8223012a3e4050e7bbfaafa6c4
  • Loading branch information
Joey Jiron authored and facebook-github-bot committed Jan 29, 2018
1 parent ae2d5b1 commit afd988f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
33 changes: 33 additions & 0 deletions local-cli/runIOS/__tests__/findMatchingSimulator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,37 @@ describe('findMatchingSimulator', () => {
version: 'iOS 10.0'
});
});

it('should return AppleTV devices if in the list', () => {
expect(findMatchingSimulator({
'devices': {
'tvOS 11.2' : [
{
'state' : 'Booted',
'availability' : '(available)',
'name' : 'Apple TV',
'udid' : '816C30EA-38EA-41AC-BFDA-96FB632D522E'
},
{
'state' : 'Shutdown',
'availability' : '(available)',
'name' : 'Apple TV 4K',
'udid' : 'BCBB7E4B-D872-4D61-BC61-7C9805551075'
},
{
'state' : 'Shutdown',
'availability' : '(available)',
'name' : 'Apple TV 4K (at 1080p)',
'udid' : '1DE12308-1C14-4F0F-991E-A3ADC41BDFFC'
}
]
}
},
'Apple TV'
)).toEqual({
udid: '816C30EA-38EA-41AC-BFDA-96FB632D522E',
name: 'Apple TV',
version: 'tvOS 11.2'
});
});
});
4 changes: 2 additions & 2 deletions local-cli/runIOS/findMatchingSimulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function findMatchingSimulator(simulators, simulatorName) {
const devices = simulators.devices;
var match;
for (let version in devices) {
// Making sure the version of the simulator is an iOS (Removes Apple Watch, etc)
if (version.indexOf('iOS') !== 0) {
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
continue;
}
for (let i in devices[version]) {
Expand Down
18 changes: 16 additions & 2 deletions local-cli/runIOS/runIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ const findXcodeProject = require('./findXcodeProject');
const findReactNativeScripts = require('../util/findReactNativeScripts');
const parseIOSDevicesList = require('./parseIOSDevicesList');
const findMatchingSimulator = require('./findMatchingSimulator');
const getBuildPath = function(configuration = 'Debug', appName, isDevice) {
return `build/Build/Products/${configuration}-${isDevice ? 'iphoneos' : 'iphonesimulator'}/${appName}.app`;
const getBuildPath = function (configuration = 'Debug', appName, isDevice) {
let device;

if (isDevice) {
device = 'iphoneos';
} else if (appName.toLowerCase().includes('tvos')) {
device = 'appletvsimulator';
} else {
device = 'iphonesimulator';
}

return `build/Build/Products/${configuration}-${device}/${appName}.app`;
};
const xcprettyAvailable = function() {
try {
Expand Down Expand Up @@ -261,6 +271,10 @@ module.exports = {
desc: "Run on a connected device, e.g. Max's iPhone",
cmd: 'react-native run-ios --device "Max\'s iPhone"',
},
{
desc: 'Run on the AppleTV simulator',
cmd: 'react-native run-ios --simulator "Apple TV" --scheme "helloworld-tvOS"',
}
],
options: [{
command: '--simulator [string]',
Expand Down

0 comments on commit afd988f

Please sign in to comment.