Skip to content

Commit aba04fa

Browse files
authored
feat(build): add API to update the iOS entitlements file (#7448)
1 parent aa94f71 commit aba04fa

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch:feat
3+
---
4+
5+
Added the `mobile::update_entitlements` function for iOS.

core/tauri-build/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ semver = "1"
3232

3333
[target."cfg(target_os = \"macos\")".dependencies]
3434
swift-rs = { version = "1.0.5", features = [ "build" ] }
35+
plist = "1"
3536

3637
[features]
3738
codegen = [ "tauri-codegen", "quote" ]

core/tauri-build/src/mobile.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,40 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()
146146
Ok(())
147147
}
148148

149+
#[cfg(target_os = "macos")]
150+
fn update_plist_file<P: AsRef<Path>, F: FnOnce(&mut plist::Dictionary)>(
151+
path: P,
152+
f: F,
153+
) -> Result<()> {
154+
let path = path.as_ref();
155+
if path.exists() {
156+
let mut plist = plist::Value::from_file(path)?;
157+
if let Some(dict) = plist.as_dictionary_mut() {
158+
f(dict);
159+
plist::to_file_xml(path, &plist)?;
160+
}
161+
}
162+
163+
Ok(())
164+
}
165+
166+
#[cfg(target_os = "macos")]
167+
pub fn update_entitlements<F: FnOnce(&mut plist::Dictionary)>(f: F) -> Result<()> {
168+
if let (Some(project_path), Ok(app_name)) = (
169+
var_os("TAURI_IOS_PROJECT_PATH").map(PathBuf::from),
170+
var("TAURI_IOS_APP_NAME"),
171+
) {
172+
update_plist_file(
173+
project_path
174+
.join(format!("{app_name}_iOS"))
175+
.join(format!("{app_name}_iOS.entitlements")),
176+
f,
177+
)?;
178+
}
179+
180+
Ok(())
181+
}
182+
149183
pub(crate) fn generate_gradle_files(project_dir: PathBuf) -> Result<()> {
150184
let gradle_settings_path = project_dir.join("tauri.settings.gradle");
151185
let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");

0 commit comments

Comments
 (0)