Short answer

When an app runs in the Simulator but crashes on an iPhone, run five launches in order (Xcode with the debugger, without it, from the Home Screen, a Release build, TestFlight) and the first one that fails tells you where to look. The usual causes are localhost URLs, paths from your Mac, memory, code behind targetEnvironment(simulator), scheme-only environment variables, work inside assert, frameworks that aren't embedded, missing entitlements and old data on the phone. Replace try! and force unwraps on those paths with errors the UI can show.

The app has run in the Simulator for weeks. Your AI tool built every screen and each one looked right. Then you plug in your iPhone, press Run, and the app flashes white and drops you back on the Home Screen. Or it opens fine from Xcode and dies the moment you tap the icon yourself.

Apple warns about this gap in plain words. Its Xcode documentation says simulators "don't replicate the performance or features of a physical device", and its release testing guide calls the Simulator "a separate device that users don't use". AI coding tools make the gap wider, because they work on your Mac and tend to reach for things that only exist there: a local server, a scheme variable, a file path, the Mac's memory.

This guide shows how to find which difference hit you, and how to fix each one. If you're holding a rejection from App Review, start with my guide to Guideline 2.1 rejections, which covers reading review crash logs. Here the iPhone is on your desk, which means you can reproduce the crash as often as you like, and that makes the job much easier.

Find the layer with five launches

Run these in order on the real iPhone and write down the first one that fails. Each launch takes away one more thing Xcode or your Mac was doing for you, so the first failure tells you which part of this guide to read.

LaunchWhat just went awaySuspects if it fails here
1. Choose the iPhone as run destination, then Product > RunYour Mac's network, disk and memorylocalhost URLs, file names, memory, missing frameworks, hardware code
2. In the scheme's Run action, Info tab, turn off Debug executable, then run againThe debuggerA slow launch killed by the watchdog
3. Unplug the phone and open the app from the Home ScreenXcode launching the processEnvironment variables and launch arguments from the scheme
4. Set the Run action's Build Configuration to Release, then runDebug-only code and settingsassert calls, #if DEBUG branches, settings that differ per configuration
5. Archive, upload, and install through TestFlightDevelopment signingEntitlements, embedded frameworks, App Store packaging

You'll find these settings under Product > Scheme > Edit Scheme. Remember to set Build Configuration back to Debug and turn Debug executable back on when you finish.

On launch 1 the debugger stops at the failing line and prints a message in the console, so read that message before you ask any tool for a fix. Later launches have no debugger, so you need another way to see what happened. Open the Console app on your Mac, select the iPhone in the sidebar, reproduce the crash and note the time. For a saved report, open Settings on the iPhone, go to the Analytics & Improvements section and tap Analytics Data. Crash logs start with your app's binary name and memory logs start with JetsamEvent_.

In Xcode 27 the tools for connected devices moved to Device Hub, which you can open with Xcode > Open Developer Tool > Device Hub or with Manage Devices in the run destination menu. Older versions of Xcode have the Devices and Simulators window instead.

localhost on an iPhone means the iPhone

AI tools like to start a local dev server and point the app at it. A Simulator app runs on your Mac and uses your Mac's network connection, so http://localhost:3000 reaches that server. On an iPhone the same address points at the phone, where nothing is listening. The request fails, which alone wouldn't crash anything, but generated code often assumes the request can't fail:

// Works in the Simulator while your dev server is running
let url = URL(string: "http://localhost:3000/api/items")!
let (data, _) = try! await URLSession.shared.data(from: url)
let items = try! JSONDecoder().decode([Item].self, from: data)

Search the project for localhost, 127.0.0.1 and every try! near a network call. Then let the failure travel to a place where the UI can show it:

struct ItemsLoader {
    let baseURL: URL

    func load() async throws -> [Item] {
        let url = baseURL.appending(path: "api/items")
        let (data, response) = try await URLSession.shared.data(from: url)
        guard (response as? HTTPURLResponse)?.statusCode == 200 else {
            throw URLError(.badServerResponse)
        }
        return try JSONDecoder().decode([Item].self, from: data)
    }
}

The caller catches the error and shows a retry button. To test a dev server from the phone, keep both devices on the same Wi-Fi and use your Mac's network address in a debug-only setting. If that server speaks plain HTTP, look at App Transport Security, and read about Apple's NSAllowsLocalNetworking key before you reach for anything broader. None of this belongs in a build you ship, so make sure the Release configuration points at your real HTTPS server.

File names and hard-coded paths

Apple's file system FAQ says APFS is case-sensitive on iOS, while on macOS case-insensitive is the default. The document is retired, but it explains a classic crash. Say the file in your project is seed.json and the generated code asks for Seed:

let url = Bundle.main.url(forResource: "Seed", withExtension: "json")!
let data = try! Data(contentsOf: url)

On the phone it returns nil and the force unwrap stops the app. Don't count on the Simulator to hide it: on a Mac with a case-insensitive disk, the iOS 18.0 and iOS 26.2 Simulators returned nil for this lookup too, as described near the end of this guide. Apple's crash pattern for this is EXC_BREAKPOINT (SIGTRAP), and the report points at the line. This small Python script walks a project, finds names used in Swift, and flags the ones that match a file only when case is ignored. Run it with the project folder as its argument:

import pathlib, re, sys

root = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else ".")
skip = {".git", ".build", "build", "DerivedData", "Pods", "node_modules"}
paths = [p for p in root.rglob("*") if not skip.intersection(p.parts)]

on_disk = {}
for p in paths:
    for name in (p.name, p.stem):
        on_disk.setdefault(name.lower(), set()).add(name)

used = re.compile(r'(?:forResource|named|NSDataAsset\(name|Image\()\s*:?\s*"([^"]+)"')
for swift in (p for p in paths if p.suffix == ".swift"):
    for number, line in enumerate(swift.read_text(errors="ignore").splitlines(), 1):
        for name in used.findall(line):
            matches = on_disk.get(name.lower(), set())
            if matches and name not in matches:
                print(f"{swift}:{number} uses '{name}', disk has {sorted(matches)}")

Every line it prints is a name to correct. It only sees string literals, so names built at runtime still need a read through by hand.

Search for /Users/ while you're there. A generated script or sample loader sometimes keeps a full path from your Mac, and that folder doesn't exist on an iPhone. Bundled files come from Bundle.main, and files the app writes belong in a directory you get from FileManager.

Memory has a low ceiling on the phone

Apple's Simulator guide says the Simulator has access to the Mac's CPU, memory and network, so it isn't an accurate test of memory use. Your phone has its own limit, and crossing it ends the app. Apple says that when the system kills a visible app for memory, it looks like the app crashed, and the jetsam report it writes contains no backtrace of your code. So if you can't find a crash report at all, look for a JetsamEvent_ file. Open it, search for reason, and check that the process name beside it is your app. A value of per-process-limit means your app crossed the limit.

Images are a common cause in generated apps, because the code loads the full file for a thumbnail. Apple's formula for an image in memory is width times height times 4 bytes. A 12-megapixel photo at 4032 by 3024 pixels works out at about 46.5 MB once decoded. Thirty of those in a photo grid, if they're all held decoded at once, comes to about 1.4 GB. Your Mac won't complain, but your phone may.

Decode images at the size you display them. Image I/O can do that without loading the full bitmap first:

import ImageIO
import UIKit

func thumbnail(at url: URL, maxPixels: CGFloat) -> UIImage? {
    let sourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary
    guard let source = CGImageSourceCreateWithURL(url as CFURL, sourceOptions) else {
        return nil
    }
    let options = [
        kCGImageSourceCreateThumbnailFromImageAlways: true,
        kCGImageSourceShouldCacheImmediately: true,
        kCGImageSourceCreateThumbnailWithTransform: true,
        kCGImageSourceThumbnailMaxPixelSize: maxPixels
    ] as CFDictionary
    guard let image = CGImageSourceCreateThumbnailAtIndex(source, 0, options) else {
        return nil
    }
    return UIImage(cgImage: image)
}

For a cell 120 points wide on a 3x screen, pass 360. While the app runs on the phone from Xcode, open the Debug navigator and watch the memory gauge as you scroll. Apple also suggests opening other apps first, which limits the memory available and gets you closer to a real user's phone.

Code the Simulator never compiled

When a feature needs a camera or motion data, an AI tool may add a fake so the Simulator keeps working:

#if targetEnvironment(simulator)
let scanner: Scanning = MockScanner()
#else
let scanner: Scanning = CameraScanner()
#endif

This pattern is reasonable, and Apple's guidance says some hardware features might not be available in a simulator. The catch is what it does to your testing. Every Simulator run used MockScanner, and CameraScanner wasn't even compiled for that build. So the first time the real branch runs is on your phone, possibly with bugs nobody has seen. List every one of these branches:

grep -rn "targetEnvironment(simulator)" --include="*.swift" .

Walk through each real branch on the phone, and call the availability APIs the frameworks give you instead of assuming the hardware is there. For the camera, one such check is UIImagePickerController.isSourceTypeAvailable(.camera). Check permission text in the same pass. Apple's technical note says an app that touches privacy-sensitive data without a usage description "will exit", and that this covers access by third-party libraries too. If the app quits the moment the real camera code starts, look for NSCameraUsageDescription in Info.plist first.

Scheme variables stop at Xcode

This is why an app can pass launches 1 and 2, then fail at launch 3. Xcode's Arguments tab lets you set environment variables for the Run action, and Apple's documentation says Xcode exports them before it runs the process. Tap the icon on the Home Screen and Xcode isn't involved, so they aren't there:

// Fine from Xcode, nil from the Home Screen and from TestFlight
let baseURL = URL(string: ProcessInfo.processInfo.environment["API_BASE_URL"]!)!

Search for ProcessInfo.processInfo.environment and move anything the app needs in production into build settings. Xcode can read values from a build configuration file and pass them into Info.plist, with a separate file per configuration. Read the value at launch with a guard and show an error screen if it's missing, so a bad build tells you what went wrong. An API key for a paid service needs a different plan, because anything inside the app bundle can be extracted. Keep that key on your own server and have the app call the server.

Release builds drop debug code

By default the scheme maps Run to the Debug configuration and Archive to Release, so a build can pass every run from Xcode and still behave differently in TestFlight. A release configuration turns on code optimizations, and in a default project it leaves out #if DEBUG branches. The Swift book adds another trap: assertions are checked only in debug builds, and in production builds the condition inside an assertion isn't evaluated. Any work placed inside assert vanishes:

// In Release this line never runs, so the store stays empty
assert(store.loadSeedData(), "Seed data failed")

// The work now runs in every configuration
let didLoad = store.loadSeedData()
assert(didLoad, "Seed data failed")

Then compare the two configurations. In your target's Build Settings, Apple says a setting that varies shows <Multiple values>, and you can expand it to see each one. Generated projects sometimes end up with a different Info.plist or a missing Release value, and this view shows it quickly. Also search for mock data and test accounts inside #if DEBUG, since a screen that only had data in Debug will open empty or crash on an unwrap in Release.

Frameworks and entitlements

An app that links a framework without embedding it crashes at launch, because the dynamic linker can't find it. The report shows EXC_CRASH (SIGABRT) and a Termination Description naming DYLD and the framework, usually something like "Library not loaded". No Swift edit will help. Open the target's General tab, find Frameworks, Libraries, and Embedded Content, and set dynamic frameworks to Embed & Sign. If the framework comes from a vendor or a third-party tool, Apple's advice is to ask that vendor. Fix "Missing Package Product" Errors in Xcode: 8 Solutions, Cheapest First covers the build-time side of the same problem.

Entitlements fail in a quieter way. If your AI tool added code for a shared App Group, but the capability was never added under Signing & Capabilities, or the identifier has a typo, this call returns nil on iOS:

guard let container = FileManager.default.containerURL(
    forSecurityApplicationGroupIdentifier: "group.com.example.myapp"
) else {
    // Log it and fall back to the app's own directory, or show an error
    return
}

Apple's documentation says the string should exactly match one in the app's entitlement. Code that force unwraps this result dies at that line. The same review applies to any other capability your tool wrote code for, such as push notifications or iCloud: the code and the capability in the project have to agree.

A phone that won't start the app at all is a different problem. If you see a signing error or Xcode says the device isn't ready, check pairing, Developer Mode and signing before you look at your code. How to Fix "No Signing Certificate Found" and Provisioning Errors in Xcode walks through the signing part.

Your phone remembers old data

Apple points out that Xcode installs builds incrementally during development, so stored data from an earlier build can linger. Your phone may hold a database written by an old version of the app, and your AI tool may have changed the data model several times since. Generated code often treats that failure as fatal:

// If the store can't be opened, the app dies at every launch
let container = try! ModelContainer(for: Item.self)

Two tests sort this out. Delete the app from the phone and install again: if the crash goes away, stored data was the cause. Keychain data survives that delete, and App Group data stays while another app in the group is installed, so a login can come back and fool you. The second test matters once you have real users: install the old build, create data, then install the new build over it. For a store shared with people, a schema change needs a migration plan, because deleting the app was only an option for you.

Replace try! with a do and catch, log the error, and show a screen that explains the problem. A launch screen that says the data couldn't be opened gives you and your testers something to report, where a crash loop gives you nothing.

Give your AI tool the evidence from the device

"It crashes on my iPhone" sends a coding agent guessing. It will wrap a few lines in try?, the crash becomes a blank screen, and you've lost the evidence. Paste the console output or the report, tell it which launch failed, and limit what it may change:

This SwiftUI app runs in the Simulator but fails on a real iPhone.
It passed launches 1 to [N] and failed on launch [N+1]:
[describe that launch]

Console output or crash report:
[paste it here]

1. Name the cause using only this evidence. If it doesn't prove the cause, say so.
2. List what in this project differs between Simulator and device:
   localhost URLs, file name case, /Users/ paths, simulator-only branches,
   scheme environment variables, assert side effects, entitlements.
3. Propose the smallest fix. Don't edit anything until I approve it.
   Don't silence the failure with try? or an empty catch.

After the fix, repeat all five launches yourself, starting from launch 1. Launches 3 and 5 are the ones a coding agent's own test run won't show you.

What the Simulator showed on a Mac

Several of the differences above were checked on macOS 26.0.1 with Xcode 26.2, using a small test app built for this guide and run in a new iPhone 17 Pro Simulator on iOS 26.2. The app bundles seed.json, a 4032 by 3024 JPEG and an asset named AppLogo, and at launch it writes what each check returned to a file. It was built in Debug and in Release. No physical iPhone was used, so the iPhone side of each row below comes from Apple's documentation.

CheckSimulator resultWhat it means
Bundle.main.url(forResource: "Seed", withExtension: "json") with seed.json in the bundlenil on iOS 26.2 and on an iOS 18.0 SimulatorWrong case failed here too, though the Mac's disk is case-insensitive
Reading a file by its full path on the Mac, under /UsersReadA Mac path works in the Simulator and has nothing to point at on a phone
UIImage(named: "applogo") for the asset AppLogonilAsset names are case-sensitive as well
assert(store.loadSeedData())Ran once in Debug, never in ReleaseMatches the Swift book; the fixed version ran in both
API_BASE_URL from the environmentnil when launched with simctl alone, set when the variable was passed inThe value exists only when the launcher provides it
containerURL(forSecurityApplicationGroupIdentifier:) with no App Group entitlementnilThe Simulator catches this one, so test it there first
os_proc_available_memory()0The Simulator reports no per-app memory limit
Full decode of the 4032 by 3024 JPEG48,771,072 bytesWidth times height times 4, as Apple's formula says
thumbnail(at:maxPixels: 360) from this guide360 by 270, 388,800 bytesAbout 125 times less memory for the same cell

The first row changes how to read the file name section. Apple's FAQ is right that iOS is case-sensitive, but the Simulators on this Mac behaved the same way, even for a file outside the app that macOS itself opened with the wrong case. So if your app runs in the Simulator, a wrong-case name in the bundle is probably not what crashed it on the phone. The check script still earns its place, because it finds those names before you run anything. It was run on a sample project and flagged a wrong-case forResource, named: and path(forResource:), skipped files under Pods and, as the guide warns, missed a name held in a variable. It also missed NSDataAsset(name: "Seed"), so the script above now checks NSDataAsset(name: too.

The memory rows are why a photo grid can pass in the Simulator. The Simulator process had no limit to report, and each full-size photo held decoded took 48.8 MB, which is the 46.5 MB above in binary megabytes. On a phone, thirty of those would be what ends the app.

The ItemsLoader and thumbnail code from this guide was compiled into the test app unchanged, in Swift 5 mode for iOS 17, with no warnings. The targetEnvironment(simulator) search worked as written in zsh. The ModelContainer line and the prompt were not tested.

Checklist before you call it fixed

  • The app runs on a real iPhone from Xcode, with and without the debugger.
  • It opens from the Home Screen with the cable unplugged.
  • A Release build runs on the phone, and a TestFlight build installs and opens.
  • No localhost, /Users/ or scheme-only values remain in shipping code.
  • The file name check prints nothing.
  • Each real branch behind targetEnvironment(simulator) has run on the phone.
  • Memory stays steady while you scroll your heaviest screen.
  • A clean install and an update over old data both work.

If you use Claude Code on a native iOS project, my Gumroad kit Claude Code + Xcode: The Production iOS Workflow Kit fits this kind of work. It's a paid product of mine with commands such as /ios-bugfix and /ios-release, plus agents for root-cause debugging and performance and memory. It can't guarantee a correct fix, and physical-device testing stays your job.

Sources