`react-native run-ios` 返回错误: 找不到 iPhone X 模拟器。

148

每当我运行react-native run-ios命令时,我会得到以下结果:

Could not find iPhone X simulator

Error: Could not find iPhone X simulator
    at resolve (calendarPractice/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
    at new Promise (<anonymous>)
    at runOnSimulator (calendarPractice/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
    at Object.runIOS [as func] (calendarPractice/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
    at Promise.resolve.then (calendarPractice/node_modules/react-native/local-cli/cliEntry.js:117:22)

然而,当我在Xcode上运行时,它可以正常工作

{
  "devicetypes" : [
    {
      "name" : "iPhone 4s",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 4s.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-4s"
    },
    {
      "name" : "iPhone 5",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 5.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-5"
    },
    {
      "name" : "iPhone 5s",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 5s.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-5s"
    },
    {
      "name" : "iPhone 6",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 6.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-6"
    },
    {
      "name" : "iPhone 6 Plus",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 6 Plus.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus"
    },
    {
      "name" : "iPhone 6s",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 6s.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-6s"
    },
    {
      "name" : "iPhone 6s Plus",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 6s Plus.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus"
    },
    {
      "name" : "iPhone 7",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 7.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-7"
    },
    {
      "name" : "iPhone 7 Plus",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 7 Plus.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-7-Plus"
    },
    {
      "name" : "iPhone 8",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 8.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-8"
    },
    {
      "name" : "iPhone 8 Plus",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 8 Plus.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-8-Plus"
    },
    {
      "name" : "iPhone SE",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone SE.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-SE"
    },
    {
      "name" : "iPhone X",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone X.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-X"
    },
    {
      "name" : "iPhone Xs",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone Xs.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-XS"
    },
    {
      "name" : "iPhone Xs Max",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone Xs Max.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-XS-Max"
    },
    {
      "name" : "iPhone Xʀ",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone Xʀ.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-XR"
    },
    {
      "name" : "iPad 2",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad 2.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-2"
    },
    {
      "name" : "iPad Retina",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Retina.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Retina"
    },
    {
      "name" : "iPad Air",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Air.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Air"
    },
    {
      "name" : "iPad Air 2",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Air 2.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Air-2"
    },
    {
      "name" : "iPad (5th generation)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad (5th generation).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad--5th-generation-"
    },
    {
      "name" : "iPad Pro (9.7-inch)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Pro (9.7-inch).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-"
    },
    {
      "name" : "iPad Pro (12.9-inch)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Pro (12.9-inch).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro"
    },
    {
      "name" : "iPad Pro (12.9-inch) (2nd generation)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Pro (12.9-inch) (2nd generation).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro--12-9-inch---2nd-generation-"
    },
    {
      "name" : "iPad Pro (10.5-inch)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Pro (10.5-inch).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro--10-5-inch-"
    },
    {
      "name" : "iPad (6th generation)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad (6th generation).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad--6th-generation-"
    },
    {
      "name" : "iPad Pro (11-inch)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Pro (11-inch).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro--11-inch-"
    },
    {
      "name" : "iPad Pro (12.9-inch) (3rd generation)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPad Pro (12.9-inch) (3rd generation).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPad-Pro--12-9-inch---3rd-generation-"
    },
    {
      "name" : "Apple TV",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/AppleTVOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple TV.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p"
    },
    {
      "name" : "Apple TV 4K",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/AppleTVOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple TV 4K.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-4K"
    },
    {
      "name" : "Apple TV 4K (at 1080p)",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/AppleTVOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple TV 4K (at 1080p).simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-1080p"
    },
    {
      "name" : "Apple Watch - 38mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch - 38mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm"
    },
    {
      "name" : "Apple Watch - 42mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch - 42mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm"
    },
    {
      "name" : "Apple Watch Series 2 - 38mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch Series 2 - 38mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-38mm"
    },
    {
      "name" : "Apple Watch Series 2 - 42mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch Series 2 - 42mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-42mm"
    },
    {
      "name" : "Apple Watch Series 3 - 38mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch Series 3 - 38mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-38mm"
    },
    {
      "name" : "Apple Watch Series 3 - 42mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch Series 3 - 42mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-42mm"
    },
    {
      "name" : "Apple Watch Series 4 - 40mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch Series 4 - 40mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-4-40mm"
    },
    {
      "name" : "Apple Watch Series 4 - 44mm",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/Apple Watch Series 4 - 44mm.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-4-44mm"
    }
  ],
  "runtimes" : [
    {
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/Runtimes\/iOS.simruntime",
      "availabilityError" : "",
      "buildversion" : "16B91",
      "availability" : "(available)",
      "isAvailable" : true,
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-12-1",
      "version" : "12.1",
      "name" : "iOS 12.1"
    },
    {
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/AppleTVOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/Runtimes\/tvOS.simruntime",
      "availabilityError" : "",
      "buildversion" : "16J602",
      "availability" : "(available)",
      "isAvailable" : true,
      "identifier" : "com.apple.CoreSimulator.SimRuntime.tvOS-12-1",
      "version" : "12.1",
      "name" : "tvOS 12.1"
    },
    {
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/WatchOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/Runtimes\/watchOS.simruntime",
      "availabilityError" : "",
      "buildversion" : "16R591",
      "availability" : "(available)",
      "isAvailable" : true,
      "identifier" : "com.apple.CoreSimulator.SimRuntime.watchOS-5-1",
      "version" : "5.1",
      "name" : "watchOS 5.1"
    }
  ],
  "devices" : {
    "com.apple.CoreSimulator.SimRuntime.watchOS-5-1" : [
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple Watch Series 2 - 38mm",
        "udid" : "01AFDEF7-63B6-465C-A02A-44EE4A07EABA",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple Watch Series 2 - 42mm",
        "udid" : "BE62C985-DEE2-46EC-8962-A582D537EEE0",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple Watch Series 3 - 38mm",
        "udid" : "078BF157-30FA-41D1-94FA-6B1686E03085",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple Watch Series 3 - 42mm",
        "udid" : "E4CE652E-0185-4C59-B965-BED5FCEE7C76",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple Watch Series 4 - 40mm",
        "udid" : "6621323A-A9DE-4BCB-AC97-54C8C33B0158",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple Watch Series 4 - 44mm",
        "udid" : "D89037A3-66A0-43C1-90BA-E7C76CA0D724",
        "availabilityError" : ""
      }
    ],
    "com.apple.CoreSimulator.SimRuntime.tvOS-12-1" : [
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple TV",
        "udid" : "AFAA21B8-BD4A-45EA-B0FF-E9915FE9B926",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple TV 4K",
        "udid" : "EBB88F2E-CFFE-4981-A736-7A7C0B85643D",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "Apple TV 4K (at 1080p)",
        "udid" : "F0B73E8A-986E-447E-B37A-2F46096DEFF6",
        "availabilityError" : ""
      }
    ],
    "com.apple.CoreSimulator.SimRuntime.iOS-12-1" : [
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 5s",
        "udid" : "F870B7FA-6DDA-4336-89AD-68A402844188",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 5s",
        "udid" : "6627ADE5-F8C1-4AE5-BD6F-3AEDDC0B7B63",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 6",
        "udid" : "05574997-ACAD-40CA-A3D7-5624D53F00FA",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 6 Plus",
        "udid" : "93237078-CA6D-4F97-93F9-779809700018",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 6s",
        "udid" : "9B50FE18-4F49-4EA4-80F0-DF498A667D33",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 6s Plus",
        "udid" : "D4640B6D-97DC-4CA1-BE63-C5403159A3D4",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 7",
        "udid" : "6E9EEC00-3291-42B4-B04A-BA3487F9CD5F",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 7 Plus",
        "udid" : "6DA1C3CF-1D1F-4DEF-9B74-2C40D5FB5881",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 8",
        "udid" : "E19386B9-469A-450B-9CD2-B4FE8687DCF9",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 8 Plus",
        "udid" : "6D36DF76-8ED9-41A2-9E1A-0BA48B92C26E",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone SE",
        "udid" : "EE4818DF-F817-4441-8A1C-BE1B99303E10",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone X",
        "udid" : "85B78A8F-C32B-4493-BDD1-65ECA3F77C86",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone X",
        "udid" : "CA12C337-4F66-4C6C-ACE5-7F7EACCBC39A",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone XS",
        "udid" : "8BBCE315-2F4C-4132-8E53-28AF52401C8E",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone XS Max",
        "udid" : "4E77C62F-AB1F-4EDE-839B-53F70CAFC79E",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone XR",
        "udid" : "28D12ABE-3355-4862-960A-0FE5FFE41C7B",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Air",
        "udid" : "94485C88-BCEB-456A-95DC-5F8C3DA8D181",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Air 2",
        "udid" : "CF2C787D-A378-4AB9-B334-F7B24E94AF4D",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad (5th generation)",
        "udid" : "DFE602A5-EC68-4585-8AB0-C045A9843D29",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro (9.7-inch)",
        "udid" : "5A3F3EAC-F788-49F1-A753-5D34A9990F0B",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro (12.9-inch)",
        "udid" : "EF6EBE34-0A85-4FF0-8A45-7BA418A0CC0C",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro (12.9-inch) (2nd generation)",
        "udid" : "FBA940F8-FD85-4D5E-A570-EB4F3A56E1F9",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro (10.5-inch)",
        "udid" : "8AE4AAED-ECE0-4984-9679-8D3022064692",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad (6th generation)",
        "udid" : "1121363D-EF49-4AC0-9E46-5C30318A24A2",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro (11-inch)",
        "udid" : "038FECC0-8711-46E3-B601-8F88F2F4AD7D",
        "availabilityError" : ""
      },
      {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro (12.9-inch) (3rd generation)",
        "udid" : "12DC911F-2F45-4767-BC1A-6F1D0C8D9F3D",
        "availabilityError" : ""
      }
    ]
  },
  "pairs" : {
    "C9B69F4A-6A9D-44F3-A6BC-56BFA2F8B83F" : {
      "watch" : {
        "name" : "Apple Watch Series 4 - 44mm",
        "udid" : "D89037A3-66A0-43C1-90BA-E7C76CA0D724",
        "state" : "Shutdown"
      },
      "phone" : {
        "name" : "iPhone XS Max",
        "udid" : "4E77C62F-AB1F-4EDE-839B-53F70CAFC79E",
        "state" : "Shutdown"
      },
      "state" : "(active, disconnected)"
    },
    "5327B65F-29E7-42D0-9861-FF31428F3218" : {
      "watch" : {
        "name" : "Apple Watch Series 4 - 40mm",
        "udid" : "6621323A-A9DE-4BCB-AC97-54C8C33B0158",
        "state" : "Shutdown"
      },
      "phone" : {
        "name" : "iPhone XS",
        "udid" : "8BBCE315-2F4C-4132-8E53-28AF52401C8E",
        "state" : "Shutdown"
      },
      "state" : "(active, disconnected)"
    }
  }

你的Xcode版本是多少? - sdkcy
是的,有那个片段! - Seongmin Choo
你能在终端上运行这个命令 xcrun simctl list --json 并将结果添加到你的问题中吗?这样我们就可以了解发生了什么事情。 - sdkcy
是的,我刚刚添加了。 - Seongmin Choo
我回答了,因为评论栏里太长了。请尝试并告诉我结果。 - sdkcy
显示剩余6条评论
26个回答

119
为了解决这个错误,只需要使用npm重新安装项目和节点模块。运行以下命令:npm install。然后它将显示一系列警告,为了解决它们,请使用以下命令:npm audit fix。这应该可以解决所有问题,并允许你运行iOS模拟器:react-native run-ios

4
这与npm无关,它仅会安装或审核节点模块。 - Firu
19
这对我有用...没有采用被接受的答案。谢谢! - RiddlerDev
2
@Firu 然而,现在至少有三个人发现这是解决方法。 - Rob Osborne
3
这对我没有用。react-native --version -> react-native-cli: 2.0.1 react-native: 0.57.7 react-native info -> macOS 10.14.4 平台:iOS 12.2 Xcode: 10.2/10E125 - Gianfranco P.
4
我认为这应该是正确的答案。改动 node_modules 文件不应该是一个有效的答案。当你因为任何原因删除 node_modules 文件夹时,这样做会让你后悔。 - Bathan
显示剩余8条评论

109

编辑过: 我复制了您输出JSON的设备部分,并嵌入到了我的/node_modules/react-native/local-cli/runIOS/runIOS.js中。

function runOnSimulator(xcodeProject, args, scheme) {
return new Promise(resolve => {
    try {
        var simulators = {devices section of your json}; //Here
    } catch (e) {
        console.log("e", e);
        throw new Error('Could not parse the simulator list output');
    }

    const selectedSimulator = findMatchingSimulator(simulators, args.simulator);
    console.log("selected", selectedSimulator);
    if (!selectedSimulator) {
        throw new Error(`Could not find ${args.simulator} simulator`);
    }
    ...

最后,它给出了与你的相同的错误。所以我想出了解析设备版本不同的方法。在你的设备中,版本是;

"com.apple.CoreSimulator.SimRuntime.tvOS-12-1" //for tvOS
"com.apple.CoreSimulator.SimRuntime.iOS-12-1" // for iOS

但在 React Native 中,会像这样检查该版本值(/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js);

// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
    continue;
}

所以React Native无法识别。
如果我们使用以下代码进行更改;

// Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
    continue;
}

问题已解决。我在我的电脑上使用您的 JSON 数据进行了检查,它可以正常工作。


24
讨厌这个方法居然行得通——有没有更持久的解决方案? - Kevin Grant
2
如果有人在运行 iPhone XR(即 react-native run-ios --simulator='iPhone XR')时遇到问题,请使用以下命令:react-native run-ios --simulator='iPhone Xʀ'。请注意,小写字母 r 是无效的。 - Mix Master Mike
4
长期修复方案是等待下一版react-native-cli的发布,其中已经修复了这个问题。https://github.com/react-native-community/react-native-cli/pull/274 - wbharding
4
这怎么能是答案?!?!你不能这样随意搞插件。 - arled
2
这个不再起作用了。截至今天,runIOS文件夹不在node_modules的react-native文件夹中。还有其他解决方法吗? - Akio
显示剩余6条评论

79

问题

如果您使用最新的Xcode(11)尝试此操作,则没有iPhone X!

单独运行模拟器,在顶部菜单下查找“硬件”,“设备”,“iOS 13.0”。

  • 您将看到:
  • iPhone 8
  • iPhone 8 Plus
  • iPhone XS
  • iPhone XS Max
  • iPhone XR
  • ...和一些iPad

当执行run-ios时,react-native被设计为匹配请求的设备。

内部硬编码的默认值是iPhone X。

尝试匹配请求设备的函数位于:

/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/findMatchingSimulator.js

该函数被设计为给定一个设备和一个可选的版本号。

如果无法找到给定的设备和版本,则默认使用列表中的第一个设备进行匹配。

但是...实际上,第一个设备是手表,并且任何手表都被排除在匹配之外,因此此函数将返回null。

解决方案1-使用现有的Xcode设备

首先按照上述描述单独运行模拟器,并记下想要的iPhone或iPad。

然后将此名称作为可选参数传递给run-ios命令行命令,如下所示:

react-native run-ios --simulator="iPhone 8"

解决方案2-添加新的Xcode iOS设备

根据Xcode 11 Release Notes文档所述:
“Xcode不再默认创建所有可用的iOS模拟器设备。取而代之的是,仅创建一组最常用的设备。要创建其他设备或多个设备实例,请打开“设备”窗口,选择模拟器,单击“+”按钮,输入名称,然后选择相关设备类型和操作系统版本。在终端中,执行xcrun simctl create命令,例如,xcrun simctl create "My iPhone 7" "iPhone 7" iOS13.0. (49428617)”。
在Xcode中,您需要添加一个名为“iPhone X”的新设备。
此外,我在此处回答:React Native Issue#2328.

1
非常感谢,你救了我们的一天。相比手动配置更改,这是iOS 13+情况下最简单且最准确的解决方案。个人认为应将其标记为被接受的答案。 - Parth Manaktala
6
这应该是被接受的答案,同时需要简要说明如何将RN默认设置从iPhone X更改。 - nosequeldeebee
1
iOS 13.0模拟器现在不再包含除最常用设备之外的所有可用设备,如果您需要其他设备(例如iPhone 7、iPhone X),则需要手动创建它们。参考链接:https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes - Akio
这是固定的,应该是主要答案。 - Jay
我只是在XCode中直接将iPhone X添加到可用设备列表中。现在它可以被找到了! - bergjs
显示剩余2条评论

48

临时解决方法:

步骤1:打开文件/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

步骤2:更改一行代码,从这个:

if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
  continue;
}

到这个:

if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
  continue;
}

步骤3:运行react-native run-ios(您可能需要运行两次,并且如果在以前的构建中已经运行,请不要忘记关闭Metro Bundler [在后台运行的控制台]!)

问题在于,在更新Xcode后,模拟器命名空间被添加到设备版本列表中。React Native构建程序没有预期到这些命名空间 - 因此导致构建失败。


1
我找不到 runIOS 目录。有什么建议吗? - Naman Jain
使用 --verbose 标志运行 react-native run-ios 命令。它将指示上述逻辑所在的文件。 - Grzegorz Pawlik

37

更新到Xcode 11后,xcrun返回true或false,而不是以前的YES或NO。

前往/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js,并在其中查找find

if (
   simulator.availability !== '(available)' &&
   simulator.isAvailable !== 'YES'
 ) {
  continue;
}

并将其更改为

if (
   simulator.availability !== '(available)' &&
   simulator.isAvailable !== true
 ) {
  continue;
}

3
这对我也起作用了。找到它在不同的目录下。node_modules/@react-native-community/cli/build/commands/runIOS/findMatchingSimulator.js - user781404
1
他们又改了它(什么鬼)/node_modules/@react-native-community/cli-platform-ios/build/commands/runIOS/findMatchingSimulator.js - Oliver Dixon
我找不到(wtf)。 - Forhad
太糟糕了。这里也是一样的情况。在早期版本的XCode中,我不得不将version.startsWith更改为version.includes,现在已经修复了。现在,在几行代码之后,将“YES”更改为true...一个永无止境的故事。 - cokron
不得不在社区包中进行更改,已经生效,谢谢。 - matt93

34

您的计算机上没有iPhone X模拟器,很可能是因为您更新了Xcode。您可以像下面这样简单传递可用模拟器的名称:

react-native run-ios --simulator="iPhone 11"

要检查可用的模拟器,您可以打开Xcode并检查设备列表,如下所示:

在此输入图片描述


10

打开文件 /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

若!version.startsWith('iOS') - > 则!version.includes('iOS')


9
我在Xcode中没有安装iPhone X模拟器,只需在Xcode中添加iPhone X作为新的模拟器即可解决问题。
在Xcode中:转到“窗口”,然后转到“设备和模拟器”。 点击模拟器选项卡。 单击左下角的“+”按钮并添加iPhone X。
希望这个修复方法对你来说像我一样容易。

对我来说,这很容易。 - Chris

9

当我将Xcode更新到11版本后,我遇到了相同的问题。

解决方法可以是将iPhone X模拟器添加到您的列表中。

  • 选择模拟器 -> 硬件 -> 设备管理器(将弹出一个窗口)

  • 选择“模拟器” -> (左下角)+(加号,位于“筛选器”旁边),然后添加一个新模拟器,

  • 模拟器名称:iPhone X 设备类型:选择iPhone X。

这对我有用。


1
这是正确的2019解决方案。 - sospedra
绝对是正确的方法。但遇到了两个小问题:1- 必须将我的新“iPhone X”模拟器与iOS 12.4运行时配对 2- 必须在node_modules/@react-native-community/cli/build/commands/runIOS/findMatchingSimulator.js中用simulator.isAvailable !== true替换simulator.isAvailable !== 'YES' - eightyfive

8

当我将 Xcode 10 升级至 Xcode 11 时,我也遇到了同样的错误。但是为模拟器版本指定特定的版本对我来说是一个快速解决方法。

首先列出所有可用的 iOS 模拟器:

  xcrun simctl list devices | grep iPhone | grep -v unavailable | cut -d'(' -f1

结果 输出

然后选择一个来运行 react-native,例如

 react-native run-ios --simulator='iPhone 11 Pro Max'

我认为这应该可以工作,但对我来说没有,我尝试过使用相关的模拟器打开和关闭。 - Harry Moreno

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接