Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

xtool.git / Documentation / xtool.docc / Control.md

Control.md6.2 KiBRenderedCodeRaw
1# Control your app's structure
2
3Add resources, modify your `Info.plist`, and more.
4
5## Overview
6
7When building your app, xtool provides many knobs to add resources and modify files in its `.app` bundle. This article explains how to perform some common tasks along these lines.
8
9Many of the tasks here involve modifying the `xtool.yml` file. The default `xtool new` template should generate this file for you. If you don't have it, make sure you create one first.
10
11```bash
12cat > xtool.yml << EOF
13version: 1
14bundleID: com.example.Hello
15EOF
16```
17
18## Change your bundle ID
19
20You can update your app's bundle ID by editing the `bundleID` field in `xtool.yml`.
21
22> Note:
23>
24> xtool adds a prefix to your bundle ID when signing and installing the app on a real device. For example, it may update the above bundle id to `XTL-1234.com.example.Hello`. This is because, at least with free accounts (those not enrolled in the Apple Developer Program), two accounts cannot use the same bundle ID. Prefixing ensures that if you share your app with someone else, they won't run into a bundle ID conflict when installing it.
25>
26> With additional engineering effort, this limitation could be lifted for paid Developer Program users by leveraging wildcard provisioning profiles. If you have a concrete use case for this and/or wish to contribute, please [file an issue](https://github.com/xtool-org/xtool/issues/new).
27
28## Customize Info.plist
29
30xtool automatically generates a bare-bones `Info.plist` file for you. However, you may need to add new `Info.plist` keys or edit existing ones.
31
32To do this, create an `Info.plist` file in your project containing just the keys you want to add/update, and tell xtool about it by adding the `infoPath` key:
33
34```yaml
35infoPath: path/to/Info.plist
36```
37
38> Tip:
39>
40> After running `xtool dev [build]`, you can inspect the built app bundle at `./xtool/YourApp.app` to view its `Info.plist` and other resources.
41
42For example, you might create an `Info.plist` file that looks something like
43
44```plist
45<?xml version="1.0" encoding="UTF-8"?>
46<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
47<plist version="1.0">
48<dict>
49 <key>UISupportedInterfaceOrientations</key>
50 <array>
51 <string>UIInterfaceOrientationLandscapeLeft</string>
52 <string>UIInterfaceOrientationLandscapeRight</string>
53 </array>
54 <key>CFBundleDisplayName</key>
55 <string>My App</string>
56</dict>
57</plist>
58```
59
60- The default `Info.plist` has a `UISupportedInterfaceOrientations` value of portrait. This will replace it with landscape-only.
61- We don't include a `CFBundleDisplayName` by default, so this will add the key and specify a display name of "My App".
62
63## Copy resources (SwiftPM)
64
65If you need to include non-code resource files, like images, the easiest way to do so is to use [SwiftPM Resources](https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package). These "just work" with xtool.
66
67For example, if you have `Sources/Hello/Blob.png`, you can include it in your app by updating the `targets` in your `Package.swift` to
68
69```swift
70targets: [
71 .target(
72 name: "Hello",
73 resources: [.copy("Blob.png")]
74 ),
75]
76```
77
78Then, to draw it on screen, you can use
79
80```swift
81Image("Blob", bundle: Bundle.module)
82```
83
84## Copy resources (top level)
85
86SwiftPM resources are copied into `.bundle` directories nested inside your `.app`. Sometimes, you need to place a file in a specific location in the app directory instead.
87
88To achieve this, you can include a `resources` array in your `xtool.yml` containing a list of files that should be directly included at the root level of the app bundle.
89
90For example, if you use Firebase, you usually need to include a [`GoogleServices-Info.plist`](https://firebase.google.com/docs/ios/setup#add-config-file) file in your root bundle. If you saved this file in your project directory at `./Resources/GoogleServices-Info.plist`, you can update your `xtool.yml` with
91
92```yaml
93resources:
94- Resources/GoogleServices-Info.plist
95```
96
97The file will be copied to `Hello.app/GoogleServices-Info.plist`.
98
99## Add an app icon
100
101Say your app icon is saved at `Resources/AppIcon.png`. You can make this your app icon by setting the `iconPath` key in `xtool.yml`:
102
103```yaml
104iconPath: Resources/AppIcon.png
105```
106
107> Tip:
108>
109> Your app icon must be a png, and it should ideally have a resolution of 1024x1024px.
110
111## Add entitlements
112
113You may need to add special [entitlements](https://developer.apple.com/documentation/bundleresources/entitlements) to your app, for example you need the `com.apple.developer.homekit` entitlement in order to connect to HomeKit devices.
114
115First create an `App.entitlements` file with the necessary entitlements:
116
117```plist
118<?xml version="1.0" encoding="UTF-8"?>
119<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
120<plist version="1.0">
121<dict>
122 <key>com.apple.developer.homekit</key>
123 <true/>
124</dict>
125</plist>
126```
127
128Then, tell xtool about it via `xtool.yml`:
129
130```yaml
131entitlementsPath: App.entitlements
132```
133
134> Troubleshooting:
135>
136> There are a number of situations in which xtool may not be able to successfully apply an entitlement to your app.
137>
138> - Some entitlements, such as [Network Extension](https://developer.apple.com/documentation/bundleresources/entitlements/com.apple.developer.networking.networkextension), don't work with free developer accounts. You might need to enrol in one of the Apple Developer Programs to use these.
139> - Other entitlements, like [User Notifications Filtering](https://developer.apple.com/documentation/bundleresources/entitlements/com.apple.developer.usernotifications.filtering), require special permission from Apple. If you do have the appropriate permission, these may or may not work with xtool.
140> - Many entitlements require specific "Capabilities" to be enabled on your app in the Developer Services portal. xtool handles this for you, but we need to add code to xtool for each Entitlement-Capability mapping. If you run into a Capability that we don't handle yet, please let us know.
141>
142> Entitlements are a large surface area. If you find any bugs or missing functionality, please [create a GitHub Issue](https://github.com/xtool-org/xtool/issues/new/choose).