Debian Codegraph @

docs/en/reference/platforms/iOS/xcode.md

raw
1 # iOS Xcode project
2
3 <table class="host-platform-support-table">
4 <colgroup>
5 <col style="width: 11%" />
6 <col style="width: 10%" />
7 <col style="width: 7%" />
8 <col style="width: 5%" />
9 <col style="width: 6%" />
10 <col style="width: 5%" />
11 <col style="width: 5%" />
12 <col style="width: 7%" />
13 <col style="width: 11%" />
14 <col style="width: 7%" />
15 <col style="width: 10%" />
16 </colgroup>
17 <thead>
18 <tr>
19 <th colspan="11"><a href="../../../../reference/platforms">Host Platform Support</a></th>
20 </tr>
21 <tr>
22 <th colspan="2">macOS</th>
23 <th colspan="5">Windows</th>
24 <th colspan="4">Linux</th>
25 </tr>
26 <tr>
27 <th>x86‑64</th>
28 <th>arm64</th>
29 <th>x86</th>
30 <th colspan="2">x86‑64</th>
31 <th colspan="2">arm64</th>
32 <th>x86</th>
33 <th>x86‑64</th>
34 <th>arm</th>
35 <th>arm64</th>
36 </tr>
37 </thead>
38 <tbody>
39 <tr>
40 <td>{{ ci_tested }}</td>
41 <td>{{ ci_tested }}</td>
42 <td></td>
43 <td colspan="2"></td>
44 <td colspan="2"></td>
45 <td></td>
46 <td></td>
47 <td></td>
48 <td></td>
49 </tr>
50 </tbody>
51 </table>
52
53 When generating an iOS project, Briefcase produces an Xcode project.
54
55 ## Icon format
56
57 iOS projects use `.png` format icons. An application must provide icons of the following sizes:
58
59 * 20px
60 * 29px
61 * 40px
62 * 58px
63 * 60px
64 * 76px
65 * 80px
66 * 87px
67 * 120px
68 * 152px
69 * 167px
70 * 180px
71 * 640px
72 * 1024px
73 * 1280px
74 * 1920px
75
76 The icon will also be used to populate the splash screen. You can specify a background color for the splash screen using the `splash_background_color` configuration setting.
77
78 iOS projects do not support installer images.
79
80 ## Colors
81
82 iOS allows for some customization of the colors used by your app:
83
84 * [`splash_background_color`][] is the color of the splash background that displays while an app is loading.
85
86 ## Additional options
87
88 The following options can be provided at the command line when producing iOS projects:
89
90 ### run
91
92 #### `-d <device>` / `--device <device>`
93
94 The device simulator to target. Can be either a UDID, a device name (e.g., `"iPhone 11"`), or a device name and OS version (`"iPhone 11::iOS 13.3"`).
95
96 ## Application configuration
97
98 The following options can be added to the `tool.briefcase.app.<appname>.iOS.app` section of your `pyproject.toml` file.
99
100 ### `info`
101
102 A property whose sub-attributes define keys that will be added to the app's `Info.plist` file. Each entry will be converted into a key in the entitlements file. For example, specifying:
103
104 ```python
105 info."UIFileSharingEnabled" = true
106 ```
107
108 will result in an `Info.plist` declaration of:
109
110 ```text
111 <key>UIFileSharingEnabled</key><true/>
112 ```
113
114 Any Boolean or string value can be used for an `Info.plist` value.
115
116 ### `min_os_version`
117
118 The minimum iOS version that the app will support. This controls the value of `IPHONEOS_DEPLOYMENT_TARGET` used when building the app.
119
120 ## Permissions
121
122 Briefcase cross-platform permissions map to the following [`info`][] keys:
123
124 * [`permission.bluetooth`][permissionbluetooth]: `NSBluetoothAlwaysUsageDescription`
125 * [`permission.camera`][permissioncamera]: `NSCameraUsageDescription`
126 * [`permission.microphone`][permissionmicrophone]: `NSMicrophoneUsageDescription`
127 * [`permission.coarse_location`][permissioncoarse_location]:
128 * `NSLocationDefaultAccuracyReduced=True`
129 * `NSLocationWhenInUseUsageDescription` if `fine_location` is not defined
130 * [`permission.fine_location`][permissionfine_location]:
131 * `NSLocationDefaultAccuracyReduced=False`
132 * `NSLocationWhenInUseUsageDescription`
133 * [`permission.background_location`][permissionbackground_location]:
134 * `NSLocationAlwaysAndWhenInUseUsageDescription`
135 * `NSLocationWhenInUseUsageDescription` if neither [`permission.fine_location`][permissionfine_location] or [`permission.coarse_location`][permissioncoarse_location] is set
136 * `UIBackgroundModes` will include `location` and `processing`
137 * [`permission.photo_library`][permissionphoto_library]: `NSPhotoLibraryAddUsageDescription`
138
139 ## Platform quirks
140
141 ### Availability of third-party packages { #ios-third-party-packages }
142
143 Briefcase is able to use third-party packages in iOS apps. As long as the package is available on PyPI, or you can provide a wheel file for the package, it can be added to the [`requires`][] declaration in your `pyproject.toml` file and used by your app at runtime.
144
145 If the package is pure Python (i.e., it does not contain a binary library), that's all you need to do. To check whether a package is pure Python, look at the PyPI downloads page for the project; if the wheels provided are have a `-py3-none-any.whl` suffix, then they are pure Python wheels. If the wheels have version and platform-specific extensions (e.g., `-cp311-cp311-macosx_11_0_universal2.whl`), then the wheel contains a binary component.
146
147 If the package contains a binary component, that wheel needs to be compiled for iOS. PyPI allows projects to upload iOS-compatible wheels (identified by suffixes like `-cp314-cp314-ios_15_4_arm64_iphoneos.whl` or `-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl`). However, at this time, most projects do not provide iOS-compatible wheels.
148
149 This is expected to improve over time. In the mean time, Briefcase uses a [secondary repository](https://anaconda.org/beeware/repo) to store some popular pre-compiled iOS wheels. This repository is maintained by the BeeWare project, and as a result, it does not have binary wheels for *every* package that is available on PyPI, or even every *version* of every package that is on PyPI. If you see the message:
150
151 ```console
152 ERROR: Could not find a version that satisfies the requirement <package name> (from versions: none)
153 ERROR: No matching distribution found for <package name>
154 ```
155
156 then the package (or the version that you've specified) probably isn't supported yet.
157
158 It is *usually* possible to compile any binary package wheels for iOS, depending on the requirements of the package itself. If the package has a dependency on other binary libraries (e.g., something like `libjpeg` that isn't written in Python), those libraries will need to be compiled for iOS as well. However, if the library requires build tools that don't support iOS, such as a compiler that can't target iOS, or a PEP517 build system that doesn't support cross-compilation, it may not be possible to build an iOS wheel.
159
160 The recommended way to build iOS-compatible wheels is to use [cibuildwheel](https://cibuildwheel.pypa.io/en/stable/platforms/#ios). Despite the name, the tool is not limited to CI environments; it can be run locally on macOS machines. Many projects already use cibuildwheel to manage publication of binary wheels. For those projects, it may be possible to generate iOS wheels by invoking `cibuildwheel --platform=ios`. Some modifications of the cibuildwheel configuration may be necessary to provide iOS-specific customizations.
161
162 The BeeWare Project also provides the [Mobile Forge](https://github.com/beeware/mobile-forge) project to assist with cross-compiling iOS binary wheels for the [secondary package repository](https://anaconda.org/beeware/repo). This project is mostly of historical significance; the BeeWare team is now focused on contributing iOS support upstream, rather than maintaining independent packaging efforts. If you would like a project to officially support iOS, you should open a feature request with that project requesting iOS support, and consider providing a PR to contribute that support.
163
164 ### Requirements cannot be provided as source tarballs
165
166 Briefcase *cannot* install packages published as source tarballs into an iOS app, even if the package is a pure Python package that would produce a `py3-none-any` wheel. This is an inherent limitation in the use of source tarballs as a distribution format.
167
168 If you need to install a package in an iOS app that is only published as a source tarball, you'll need to compile that package into a wheel first. If the package is pure Python, you can generate a `py3-none-any` wheel using `pip wheel <package name>`. If the project has a binary component, you'll need to use [cibuildwheel](https://cibuildwheel.pypa.io/en/stable/platforms/#ios) or other similar tooling to compile compatible wheels.
169
170 You can then directly add the wheel file to the [`requires`][] definition for your app, or put the wheel in a folder and add:
171
172 ```toml
173 requirement_installer_args = ["--find-links", "<path-to-wheel-folder>"]
174 ```
175
176 to your `pyproject.toml`. This will instruct Briefcase to search that folder for compatible wheels during the installation process.
177
178 ### Executable binary content in wheels
179
180 The iOS App Store has very stringent constraints on what can be included in an app bundle, and where it can be included. One of those constraints is that any executable content must be distributed as a framework, in the `Frameworks` folder of the iOS project.
181
182 Briefcase's app template will process binary wheels to satisfy this requirement. However, it will only process binary content that is executable at runtime. Some packages (NumPy is one notable example) are known to distribute additional executable files, such as statically linked `.a` libraries, in their wheel content. These files are not usable at runtime, and Briefcase will not process them. If they're present in an app bundle at time of submission to the App Store, your app will not pass app validation, raising errors like:
183
184 > Error: Validation failed Invalid bundle structure. The
185 > `.../libsomething.a` binary file is not permitted. Your app cannot
186 > contain standalone executables or libraries, other than a valid
187 > CFBundleExecutable of supported bundles.
188
189 To avoid this, you must purge any binary content from your app before submission. You can do this using the `cleanup_paths` configuration option:
190
191 ```python
192 cleanup_paths = [
193 "*/app_packages.*/**/*.a",
194 ]
195 ```
196
197 This will find and purge all `.a` content in your app's dependencies. You can add additional patterns to remove other problematic content.
198
199 ### Deployment to Simulated and Physical iOS Devices { #ios-deploy }
200
201 Briefcase provides support for deployment to simulated iOS devices through the command line.
202
203 If you want to deploy to a physical iOS device, you will need need to use Xcode through the following steps:
204
205 1. Run `briefcase open ios` in the command line. This will open your application in Xcode.
206 2. Setup your Apple Developer account with your certificate in Xcode.
207 3. In the project navigator, select your application at the top level (the root of the project).
208 4. Select the *Signing and Capabilities* tab in the editor area.
209 5. Select your Apple Developer team or individual account from the *Team* drop-down.
210 6. Select your specific device.
211 7. Press the run button.