Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

AnimationPacks: Apple-hosted asset packs on iOS 26, a stub on Android

Duarte Santosb13666d2c1bd
diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml
index 5f2cc8f91..40a9c8033 100644
--- a/.github/workflows/ios.yml
+++ b/.github/workflows/ios.yml
@@ -42,6 +42,9 @@ jobs:
# The phone build, copied into ios/App/App/public; cap sync runs pod install.
- run: npm run build:mobile
working-directory: frontend
+ # The asset pack downloader extension, until the project with it is committed (does nothing then).
+ - run: ruby ios/ci/add-asset-downloader.rb
+ working-directory: frontend
- name: Build for the simulator
working-directory: frontend/ios/App
run: |
@@ -103,6 +106,8 @@ jobs:
working-directory: frontend
- run: npm run build:mobile && rm -rf ios/App/App/public/exercise-media
working-directory: frontend
+ - run: ruby ios/ci/add-asset-downloader.rb
+ working-directory: frontend
- run: ruby ios/ci/add-ui-tests.rb
working-directory: frontend
- name: Run the UI tests
@@ -152,6 +157,8 @@ jobs:
working-directory: frontend
- run: npm run build:mobile
working-directory: frontend
+ - run: ruby ios/ci/add-asset-downloader.rb
+ working-directory: frontend
- name: Archive, unsigned
working-directory: frontend/ios/App
run: |
diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/AnimationPacksPlugin.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/AnimationPacksPlugin.java
new file mode 100644
index 000000000..55a17dcb8
--- /dev/null
+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/AnimationPacksPlugin.java
@@ -0,0 +1,47 @@
+package ch.duartesantos.opengym;
+
+import com.getcapacitor.JSObject;
+import com.getcapacitor.Plugin;
+import com.getcapacitor.PluginCall;
+import com.getcapacitor.PluginMethod;
+import com.getcapacitor.annotation.CapacitorPlugin;
+
+/**
+ * The sharper exercise animations as asset packs (frontend lib/anim-packs.js). On Android they
+ * will come through Play Asset Delivery; until then, and always in the sideloaded APK (no Play
+ * Store behind it), there are none: every call answers "unavailable" and the app shows the
+ * animations built into it. The interface is the iOS plugin's (AnimationPacksPlugin.swift), so
+ * the page needs no Android branch.
+ */
+@CapacitorPlugin(name = "AnimationPacks")
+public class AnimationPacksPlugin extends Plugin {
+
+ @PluginMethod
+ public void available(PluginCall call) {
+ JSObject ret = new JSObject();
+ ret.put("available", false);
+ call.resolve(ret);
+ }
+
+ @PluginMethod
+ public void status(PluginCall call) {
+ JSObject ret = new JSObject();
+ ret.put("state", "none");
+ call.resolve(ret);
+ }
+
+ @PluginMethod
+ public void download(PluginCall call) {
+ call.reject("asset packs are not available on Android yet", "unavailable");
+ }
+
+ @PluginMethod
+ public void remove(PluginCall call) {
+ call.resolve();
+ }
+
+ @PluginMethod
+ public void localPath(PluginCall call) {
+ call.reject("not downloaded", "unavailable");
+ }
+}
diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java
index dbd348822..a9a492d8f 100644
--- a/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java
+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java
@@ -28,6 +28,7 @@ public class MainActivity extends BridgeActivity {
registerPlugin(BackupFolderPlugin.class);
registerPlugin(BarIconsPlugin.class);
registerPlugin(DeviceAuthPlugin.class);
+ registerPlugin(AnimationPacksPlugin.class);
super.onCreate(savedInstanceState);
passSystemBarsToPage();
}
diff --git a/frontend/ios/App/AnimationPacksDownloader/AnimationPacksDownloader.entitlements b/frontend/ios/App/AnimationPacksDownloader/AnimationPacksDownloader.entitlements
new file mode 100644
index 000000000..02dde9497
--- /dev/null
+++ b/frontend/ios/App/AnimationPacksDownloader/AnimationPacksDownloader.entitlements
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyLists-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.security.application-groups</key>
+ <array>
+ <string>group.ch.opengym.app</string>
+ </array>
+</dict>
+</plist>
diff --git a/frontend/ios/App/AnimationPacksDownloader/AnimationPacksDownloader.swift b/frontend/ios/App/AnimationPacksDownloader/AnimationPacksDownloader.swift
new file mode 100644
index 000000000..5e23d28ab
--- /dev/null
+++ b/frontend/ios/App/AnimationPacksDownloader/AnimationPacksDownloader.swift
@@ -0,0 +1,16 @@
+import BackgroundAssets
+import ExtensionFoundation
+import StoreKit
+
+/**
+ * The downloader extension Background Assets runs to fetch the app's Apple-hosted asset packs
+ * (the exercise animations above 180 px, App/AnimationPacksPlugin.swift). Every pack is on
+ * demand: nothing is fetched until the app asks for the quality and figure someone picked, so
+ * the extension lets through whatever the app asks for and nothing else is ever scheduled.
+ */
+@main
+struct AnimationPacksDownloader: StoreDownloaderExtension {
+ func shouldDownload(_ assetPack: AssetPack) -> Bool {
+ return true
+ }
+}
diff --git a/frontend/ios/App/AnimationPacksDownloader/Info.plist b/frontend/ios/App/AnimationPacksDownloader/Info.plist
new file mode 100644
index 000000000..01d2ff89b
--- /dev/null
+++ b/frontend/ios/App/AnimationPacksDownloader/Info.plist
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyLists-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>openGym animations</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
+ <key>CFBundleShortVersionString</key>
+ <string>$(MARKETING_VERSION)</string>
+ <key>CFBundleVersion</key>
+ <string>$(CURRENT_PROJECT_VERSION)</string>
+ <key>BAAppGroupID</key>
+ <string>group.ch.opengym.app</string>
+ <key>BAHasManagedAssetPacks</key>
+ <true/>
+ <key>BAUsesAppleHosting</key>
+ <true/>
+ <key>EXAppExtensionAttributes</key>
+ <dict>
+ <key>EXExtensionPointIdentifier</key>
+ <string>com.apple.background-asset-downloader-extension</string>
+ </dict>
+</dict>
+</plist>
diff --git a/frontend/ios/App/App.xcodeproj/project.pbxproj b/frontend/ios/App/App.xcodeproj/project.pbxproj
index bc36bd173..3d81c5006 100644
--- a/frontend/ios/App/App.xcodeproj/project.pbxproj
+++ b/frontend/ios/App/App.xcodeproj/project.pbxproj
@@ -22,6 +22,7 @@
AA0200000000000000000006 /* RestTone.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0200000000000000000005 /* RestTone.swift */; };
AA0200000000000000000008 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = AA0200000000000000000007 /* PrivacyInfo.xcprivacy */; };
AA0300000000000000000002 /* DeviceAuthPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0300000000000000000001 /* DeviceAuthPlugin.swift */; };
+ AA0400000000000000000002 /* AnimationPacksPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0400000000000000000001 /* AnimationPacksPlugin.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -44,6 +45,8 @@
AA0200000000000000000005 /* RestTone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestTone.swift; sourceTree = "<group>"; };
AA0200000000000000000007 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
AA0300000000000000000001 /* DeviceAuthPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceAuthPlugin.swift; sourceTree = "<group>"; };
+ AA0400000000000000000001 /* AnimationPacksPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimationPacksPlugin.swift; sourceTree = "<group>"; };
+ AA0400000000000000000003 /* App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = App.entitlements; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -95,6 +98,8 @@
AA0200000000000000000003 /* RestAlertPlugin.swift */,
AA0200000000000000000005 /* RestTone.swift */,
AA0300000000000000000001 /* DeviceAuthPlugin.swift */,
+ AA0400000000000000000001 /* AnimationPacksPlugin.swift */,
+ AA0400000000000000000003 /* App.entitlements */,
AA0200000000000000000007 /* PrivacyInfo.xcprivacy */,
504EC30B1FED79650016851F /* Main.storyboard */,
504EC30E1FED79650016851F /* Assets.xcassets */,
@@ -238,6 +243,7 @@
AA0200000000000000000004 /* RestAlertPlugin.swift in Sources */,
AA0200000000000000000006 /* RestTone.swift in Sources */,
AA0300000000000000000002 /* DeviceAuthPlugin.swift in Sources */,
+ AA0400000000000000000002 /* AnimationPacksPlugin.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -375,6 +381,7 @@
baseConfigurationReference = FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 26;
INFOPLIST_FILE = App/Info.plist;
@@ -395,6 +402,7 @@
baseConfigurationReference = AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 26;
INFOPLIST_FILE = App/Info.plist;
diff --git a/frontend/ios/App/App/AnimationPacksPlugin.swift b/frontend/ios/App/App/AnimationPacksPlugin.swift
new file mode 100644
index 000000000..9806bc59c
--- /dev/null
+++ b/frontend/ios/App/App/AnimationPacksPlugin.swift
@@ -0,0 +1,174 @@
+import Foundation
+import Capacitor
+import Network
+#if canImport(BackgroundAssets)
+import BackgroundAssets
+#endif
+
+/**
+ * The sharper exercise animations, as Apple-hosted asset packs (Background Assets, iOS 26 and
+ * later): one pack per quality and figure, `anim-<px>-male` / `anim-<px>-female`, uploaded to App
+ * Store Connect and delivered by Apple, never by a server of ours (Gym visual licence: anything
+ * above 180 px reaches people only inside the store app). The packs and what is in them come from
+ * scripts/media/make-pack-manifests.mjs; inside a pack a drawing sits at `<packId>/<id>.webp`.
+ * The page side is frontend/src/lib/anim-packs.js. On an older iOS every call answers
+ * "unavailable" and the app shows its built-in animations.
+ *
+ * The app needs, in Info.plist, BAAppGroupID, BAHasManagedAssetPacks and BAUsesAppleHosting, and
+ * the downloader extension (AnimationPacksDownloader), which the system runs to fetch packs.
+ */
+@objc(AnimationPacksPlugin)
+public class AnimationPacksPlugin: CAPPlugin, CAPBridgedPlugin {
+ public let identifier = "AnimationPacksPlugin"
+ public let jsName = "AnimationPacks"
+ public let pluginMethods: [CAPPluginMethod] = [
+ CAPPluginMethod(name: "available", returnType: CAPPluginReturnPromise),
+ CAPPluginMethod(name: "status", returnType: CAPPluginReturnPromise),
+ CAPPluginMethod(name: "download", returnType: CAPPluginReturnPromise),
+ CAPPluginMethod(name: "remove", returnType: CAPPluginReturnPromise),
+ CAPPluginMethod(name: "localPath", returnType: CAPPluginReturnPromise),
+ ]
+
+ /// Only the ids the app knows: a pack id from the page goes nowhere else.
+ private static let packPattern = try! NSRegularExpression(pattern: "^anim-(240|360|480|720|1080)-(male|female)$")
+ private static let probePattern = try! NSRegularExpression(pattern: "^[0-9]{4,5}$")
+
+ private static func matches(_ re: NSRegularExpression, _ s: String) -> Bool {
+ re.firstMatch(in: s, range: NSRange(s.startIndex..., in: s)) != nil
+ }
+
+ private func packArgs(_ call: CAPPluginCall, probe needed: Bool) -> (String, String)? {
+ guard let id = call.getString("packId"), AnimationPacksPlugin.matches(AnimationPacksPlugin.packPattern, id) else {
+ call.reject("unknown pack", "failed")
+ return nil
+ }
+ let probe = call.getString("probe") ?? ""
+ if needed && !AnimationPacksPlugin.matches(AnimationPacksPlugin.probePattern, probe) {
+ call.reject("probe is required", "failed")
+ return nil
+ }
+ return (id, probe)
+ }
+
+ /// Apple-hosted packs: iOS 26 and an app that declares them.
+ private var supported: Bool {
+ guard Bundle.main.object(forInfoDictionaryKey: "BAUsesAppleHosting") as? Bool == true else { return false }
+ if #available(iOS 26.0, *) { return true }
+ return false
+ }
+
+ @objc func available(_ call: CAPPluginCall) {
+ call.resolve(["available": supported])
+ }
+
+ @objc func status(_ call: CAPPluginCall) {
+ guard let (id, probe) = packArgs(call, probe: true) else { return }
+ guard supported, let folder = localFolder(id, probe) else {
+ call.resolve(["state": "none"])
+ return
+ }
+ call.resolve(["state": "ready", "bytes": AnimationPacksPlugin.size(of: folder)])
+ }
+
+ @objc func localPath(_ call: CAPPluginCall) {
+ guard let (id, probe) = packArgs(call, probe: true) else { return }
+ guard supported, let folder = localFolder(id, probe) else {
+ call.reject("not downloaded", "unavailable")
+ return
+ }
+ call.resolve(["path": folder.path])
+ }
+
+ @objc func download(_ call: CAPPluginCall) {
+ guard let (id, _) = packArgs(call, probe: false) else { return }
+ guard supported else { call.reject("asset packs need iOS 26", "unavailable"); return }
+ let wifiOnly = call.getBool("wifiOnly") ?? true
+ #if canImport(BackgroundAssets)
+ if #available(iOS 26.0, *) {
+ Task {
+ if wifiOnly, await !AnimationPacksPlugin.onWifi() {
+ call.reject("waiting for Wi-Fi", "needs-wifi")
+ return
+ }
+ let manager = AssetPackManager.shared
+ let watcher = Task { [weak self] in
+ for await update in manager.statusUpdates(forAssetPackWithID: id) {
+ if case .downloading(_, let progress) = update {
+ self?.notifyListeners("progress", data: ["packId": id, "fraction": progress.fractionCompleted])
+ }
+ }
+ }
+ defer { watcher.cancel() }
+ do {
+ let pack = try await manager.assetPack(withID: id)
+ try await manager.ensureLocalAvailability(of: pack)
+ call.resolve()
+ } catch is CancellationError {
+ call.reject("cancelled", "cancelled")
+ } catch {
+ call.reject(error.localizedDescription, "failed")
+ }
+ }
+ return
+ }
+ #endif
+ call.reject("asset packs need iOS 26", "unavailable")
+ }
+
+ @objc func remove(_ call: CAPPluginCall) {
+ guard let (id, _) = packArgs(call, probe: false) else { return }
+ guard supported else { call.resolve(); return }
+ #if canImport(BackgroundAssets)
+ if #available(iOS 26.0, *) {
+ Task {
+ do {
+ try await AssetPackManager.shared.remove(assetPackWithID: id)
+ call.resolve()
+ } catch {
+ call.reject(error.localizedDescription, "failed")
+ }
+ }
+ return
+ }
+ #endif
+ call.resolve()
+ }
+
+ /// The folder a downloaded pack's files are in, found through one file it holds: Background
+ /// Assets reads all downloaded packs as one tree and answers for a path, not for a pack.
+ private func localFolder(_ id: String, _ probe: String) -> URL? {
+ #if canImport(BackgroundAssets)
+ if #available(iOS 26.0, *) {
+ guard let file = try? AssetPackManager.shared.url(for: "\(id)/\(probe).webp") else { return nil }
+ return file.deletingLastPathComponent()
+ }
+ #endif
+ return nil
+ }
+
+ private static func size(of folder: URL) -> Int {
+ let keys: [URLResourceKey] = [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey]
+ guard let files = FileManager.default.enumerator(at: folder, includingPropertiesForKeys: keys) else { return 0 }
+ var total = 0
+ for case let f as URL in files {
+ let v = try? f.resourceValues(forKeys: Set(keys))
+ total += v?.totalFileAllocatedSize ?? v?.fileAllocatedSize ?? 0
+ }
+ return total
+ }
+
+ /// Whether the phone is on a network that costs nothing extra (Wi-Fi or a cable), now.
+ private static func onWifi() async -> Bool {
+ await withCheckedContinuation { done in
+ let monitor = NWPathMonitor()
+ var answered = false
+ monitor.pathUpdateHandler = { path in
+ guard !answered else { return }
+ answered = true
+ monitor.cancel()
+ done.resume(returning: path.status == .satisfied && !path.isExpensive && !path.isConstrained)
+ }
+ monitor.start(queue: DispatchQueue(label: "ch.opengym.app.anim-packs.path"))
+ }
+ }
+}
diff --git a/frontend/ios/App/App/App.entitlements b/frontend/ios/App/App/App.entitlements
new file mode 100644
index 000000000..02dde9497
--- /dev/null
+++ b/frontend/ios/App/App/App.entitlements
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyLists-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.security.application-groups</key>
+ <array>
+ <string>group.ch.opengym.app</string>
+ </array>
+</dict>
+</plist>
diff --git a/frontend/ios/App/App/Info.plist b/frontend/ios/App/App/Info.plist
index 2189347e9..72afc570c 100644
--- a/frontend/ios/App/App/Info.plist
+++ b/frontend/ios/App/App/Info.plist
@@ -78,6 +78,12 @@
<string>Used to scan your gym membership QR code, and to take a photo or video of an exercise you add yourself.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Used to record the sound of a video you take of an exercise you add yourself.</string>
+ <key>BAAppGroupID</key>
+ <string>group.ch.opengym.app</string>
+ <key>BAHasManagedAssetPacks</key>
+ <true/>
+ <key>BAUsesAppleHosting</key>
+ <true/>
<key>NSFaceIDUsageDescription</key>
<string>Used to make sure it’s really you before your account is deleted.</string>
</dict>
diff --git a/frontend/ios/App/App/MainViewController.swift b/frontend/ios/App/App/MainViewController.swift
index b68593f35..a3919479a 100644
--- a/frontend/ios/App/App/MainViewController.swift
+++ b/frontend/ios/App/App/MainViewController.swift
@@ -12,6 +12,7 @@ class MainViewController: CAPBridgeViewController {
bridge?.registerPluginInstance(PrintPlugin())
bridge?.registerPluginInstance(RestAlertPlugin())
bridge?.registerPluginInstance(DeviceAuthPlugin())
+ bridge?.registerPluginInstance(AnimationPacksPlugin())
// After loadView has finished: the view is the web view only once it has.
if ProcessInfo.processInfo.arguments.contains(MainViewController.pendingProbeArgument) {
DispatchQueue.main.async { [weak self] in self?.showPendingProbe() }
diff --git a/frontend/ios/ci/add-asset-downloader.rb b/frontend/ios/ci/add-asset-downloader.rb
new file mode 100644
index 000000000..140b4e454
--- /dev/null
+++ b/frontend/ios/ci/add-asset-downloader.rb
@@ -0,0 +1,65 @@
+# Adds the Background Assets downloader extension (ios/App/AnimationPacksDownloader) to
+# App.xcodeproj and embeds it in the app: the system runs it to fetch the Apple-hosted asset
+# packs of the exercise animations (App/AnimationPacksPlugin.swift). Unlike the UI tests
+# (add-ui-tests.rb) this is a real shipping target: run it once on a machine with the xcodeproj
+# gem (it ships with CocoaPods) and commit the project it writes. Running it again changes
+# nothing. Until the result is committed, CI runs it before every build (.github/workflows/ios.yml).
+#
+# ruby frontend/ios/ci/add-asset-downloader.rb
+#
+# App Store Connect needs, before a signed build: the App Group group.ch.opengym.app on both
+# bundle ids, the extension's bundle id ch.opengym.app.AnimationPacksDownloader, and an App Store
+# provisioning profile for each (docs/MOBILE.md, "Animation packs").
+require 'xcodeproj'
+
+NAME = 'AnimationPacksDownloader'
+BUNDLE_ID = 'ch.opengym.app.AnimationPacksDownloader'
+
+dir = File.expand_path('../App', __dir__)
+proj = Xcodeproj::Project.open(File.join(dir, 'App.xcodeproj'))
+app = proj.targets.find { |t| t.name == 'App' }
+abort 'no App target' unless app
+if proj.targets.any? { |t| t.name == NAME }
+ puts "#{NAME} is already in the project"
+ exit 0
+end
+
+# An ExtensionKit extension (iOS 26): built like an app extension, packaged as one, embedded
+# under Extensions/ rather than PlugIns/.
+ext = proj.new_target(:app_extension, NAME, :ios, '26.0')
+ext.product_type = 'com.apple.product-type.extensionkit-extension'
+ext.product_reference.explicit_file_type = 'wrapper.extensionkit-extension'
+
+group = proj.main_group.new_group(NAME, NAME)
+ext.add_file_references([group.new_file("#{NAME}.swift")])
+group.new_file('Info.plist')
+group.new_file("#{NAME}.entitlements")
+
+app_settings = app.build_configurations.first.build_settings
+ext.build_configurations.each do |c|
+ s = c.build_settings
+ s['PRODUCT_NAME'] = '$(TARGET_NAME)'
+ s['PRODUCT_BUNDLE_IDENTIFIER'] = BUNDLE_ID
+ s['INFOPLIST_FILE'] = "#{NAME}/Info.plist"
+ s['GENERATE_INFOPLIST_FILE'] = 'NO'
+ s['CODE_SIGN_ENTITLEMENTS'] = "#{NAME}/#{NAME}.entitlements"
+ s['CODE_SIGN_STYLE'] = 'Automatic'
+ s['SWIFT_VERSION'] = '5.0'
+ s['IPHONEOS_DEPLOYMENT_TARGET'] = '26.0'
+ s['TARGETED_DEVICE_FAMILY'] = '1,2'
+ s['SKIP_INSTALL'] = 'YES'
+ s['MARKETING_VERSION'] = app_settings['MARKETING_VERSION']
+ s['CURRENT_PROJECT_VERSION'] = app_settings['CURRENT_PROJECT_VERSION']
+ s['LD_RUNPATH_SEARCH_PATHS'] = ['$(inherited)', '@executable_path/Frameworks', '@executable_path/../../Frameworks']
+end
+
+# Built before the app, and copied into App.app/Extensions.
+app.add_dependency(ext)
+embed = app.new_copy_files_build_phase('Embed ExtensionKit Extensions')
+embed.symbol_dst_subfolder_spec = :products_directory
+embed.dst_path = '$(EXTENSIONS_FOLDER_PATH)'
+file = embed.add_file_reference(ext.product_reference, true)
+file.settings = { 'ATTRIBUTES' => ['RemoveHeadersOnCopy'] }
+
+proj.save
+puts "added #{NAME} (#{BUNDLE_ID}), embedded in App"
diff --git a/scripts/ios/finish-ipa.sh b/scripts/ios/finish-ipa.sh
index 56627d5ee..0603e735f 100755
--- a/scripts/ios/finish-ipa.sh
+++ b/scripts/ios/finish-ipa.sh
@@ -10,6 +10,7 @@
#
# Usage:
# scripts/ios/finish-ipa.sh <App-unsigned.ipa> <dist.p12> <p12-password-file> <profile.mobileprovision> [out.ipa]
+# EXT_PROFILE=<extension.mobileprovision> ... once the IPA carries the asset pack downloader
#
# Before: the phone build with the app's animations, from the same commit as the IPA:
# cd frontend && VITE_CLIP_EXT=webp APP_MEDIA_DIR=/mnt/backup-hdd/opengym-media/build-appwebp npm run build:mobile
@@ -63,8 +64,30 @@ plistlib.dump(e, open(sys.argv[2], 'wb'))
print('profile:', p['Name'], '| team', p['TeamIdentifier'][0], '| expires', p['ExpirationDate'])
PY
+# The asset pack downloader extension (Background Assets, ios/App/AnimationPacksDownloader) is
+# signed with its own App Store profile, given as EXT_PROFILE: its bundle id and its entitlements
+# (the App Group it shares with the app) are its own.
+EXT="$APP/Extensions/AnimationPacksDownloader.appex"
+EXT_SIGN=()
+if [ -d "$EXT" ]; then
+ [ -n "${EXT_PROFILE:-}" ] || { echo "the IPA carries AnimationPacksDownloader.appex: set EXT_PROFILE to its App Store profile" >&2; exit 1; }
+ cp "$EXT_PROFILE" "$EXT/embedded.mobileprovision"
+ openssl smime -inform der -verify -noverify -in "$EXT_PROFILE" -out "$WORK/ext-profile.plist" 2>/dev/null
+ python3 - "$WORK/ext-profile.plist" "$WORK/ext-entitlements.plist" <<'PY'
+import plistlib, sys
+p = plistlib.load(open(sys.argv[1], 'rb'))
+e = dict(p['Entitlements'])
+e['get-task-allow'] = False
+assert e['application-identifier'].endswith('.ch.opengym.app.AnimationPacksDownloader'), e['application-identifier']
+assert 'group.ch.opengym.app' in e.get('com.apple.security.application-groups', []), 'the extension profile has no App Group'
+plistlib.dump(e, open(sys.argv[2], 'wb'))
+print('extension profile:', p['Name'], '| expires', p['ExpirationDate'])
+PY
+ EXT_SIGN=(--entitlements-xml-file "Extensions/AnimationPacksDownloader.appex/AnimationPacksDownloader:$WORK/ext-entitlements.plist")
+fi
+
"$RCODESIGN" sign --p12-file "$P12" --p12-password-file "$P12PASS" \
- --entitlements-xml-file "App:$WORK/entitlements.plist" "$APP"
+ --entitlements-xml-file "App:$WORK/entitlements.plist" "${EXT_SIGN[@]}" "$APP"
(cd "$WORK/ipa" && rm -f "$OUT" && python3 -m zipfile -c "$OUT" Payload)
echo "signed: $OUT ($(du -h "$OUT" | cut -f1), $CLIPS animations)"