Skip to content

Commit a4e3a9e

Browse files
Joey Jironfacebook-github-bot
authored andcommitted
fixed issue with runIOS not being able to launch tvOS app
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 facebook/react-native#17660 Differential Revision: D6806327 Pulled By: hramos fbshipit-source-id: 1a4f37058f3c5d8223012a3e4050e7bbfaafa6c4
1 parent 1cdfd61 commit a4e3a9e

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

runIOS/__tests__/findMatchingSimulator-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,37 @@ describe('findMatchingSimulator', () => {
453453
version: 'iOS 10.0'
454454
});
455455
});
456+
457+
it('should return AppleTV devices if in the list', () => {
458+
expect(findMatchingSimulator({
459+
'devices': {
460+
'tvOS 11.2' : [
461+
{
462+
'state' : 'Booted',
463+
'availability' : '(available)',
464+
'name' : 'Apple TV',
465+
'udid' : '816C30EA-38EA-41AC-BFDA-96FB632D522E'
466+
},
467+
{
468+
'state' : 'Shutdown',
469+
'availability' : '(available)',
470+
'name' : 'Apple TV 4K',
471+
'udid' : 'BCBB7E4B-D872-4D61-BC61-7C9805551075'
472+
},
473+
{
474+
'state' : 'Shutdown',
475+
'availability' : '(available)',
476+
'name' : 'Apple TV 4K (at 1080p)',
477+
'udid' : '1DE12308-1C14-4F0F-991E-A3ADC41BDFFC'
478+
}
479+
]
480+
}
481+
},
482+
'Apple TV'
483+
)).toEqual({
484+
udid: '816C30EA-38EA-41AC-BFDA-96FB632D522E',
485+
name: 'Apple TV',
486+
version: 'tvOS 11.2'
487+
});
488+
});
456489
});

runIOS/findMatchingSimulator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function findMatchingSimulator(simulators, simulatorName) {
2626
const devices = simulators.devices;
2727
var match;
2828
for (let version in devices) {
29-
// Making sure the version of the simulator is an iOS (Removes Apple Watch, etc)
30-
if (version.indexOf('iOS') !== 0) {
29+
// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
30+
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
3131
continue;
3232
}
3333
for (let i in devices[version]) {

runIOS/runIOS.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ const findXcodeProject = require('./findXcodeProject');
1515
const findReactNativeScripts = require('../util/findReactNativeScripts');
1616
const parseIOSDevicesList = require('./parseIOSDevicesList');
1717
const findMatchingSimulator = require('./findMatchingSimulator');
18-
const getBuildPath = function(configuration = 'Debug', appName, isDevice) {
19-
return `build/Build/Products/${configuration}-${isDevice ? 'iphoneos' : 'iphonesimulator'}/${appName}.app`;
18+
const getBuildPath = function (configuration = 'Debug', appName, isDevice) {
19+
let device;
20+
21+
if (isDevice) {
22+
device = 'iphoneos';
23+
} else if (appName.toLowerCase().includes('tvos')) {
24+
device = 'appletvsimulator';
25+
} else {
26+
device = 'iphonesimulator';
27+
}
28+
29+
return `build/Build/Products/${configuration}-${device}/${appName}.app`;
2030
};
2131
const xcprettyAvailable = function() {
2232
try {
@@ -261,6 +271,10 @@ module.exports = {
261271
desc: "Run on a connected device, e.g. Max's iPhone",
262272
cmd: 'react-native run-ios --device "Max\'s iPhone"',
263273
},
274+
{
275+
desc: 'Run on the AppleTV simulator',
276+
cmd: 'react-native run-ios --simulator "Apple TV" --scheme "helloworld-tvOS"',
277+
}
264278
],
265279
options: [{
266280
command: '--simulator [string]',

0 commit comments

Comments
 (0)