Enable to get data directory in iOS

This commit is contained in:
fluo10 2025-08-28 08:22:50 +09:00
parent 64aa5f2353
commit 6fe8c2bf61
4 changed files with 22 additions and 14 deletions

View file

@ -44,9 +44,9 @@ jni = "0.21.1"
ndk = "0.9.0"
[target.'cfg(target_os="ios")'.dependencies]
objc = "0.2.7"
objc-foundation = "0.1.1"
objc_id = "0.1.1"
objc2 = "0.6.2"
objc2-foundation = "0.3.1"
objc2-app-kit = "0.3.1"
[dev-dependencies]
tempfile = "3.20.0"

View file

@ -49,7 +49,7 @@ impl PartialStorageConfig {
}
}
#[cfg(target_os="android")]
fn default_android() -> Self{
pub fn default_android() -> Self{
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let mut env = vm.attach_current_thread()?;
@ -66,15 +66,22 @@ impl PartialStorageConfig {
Ok(cache_dir.to_string())
}
#[cfg(false)]
fn default_ios(){
unsafe {
let file_manager: *mut Object = msg_send![Class::get("NSFileManager").unwrap(), defaultManager];
let paths: Id<Object> = msg_send![file_manager, URLsForDirectory:1 inDomains:1];
let first_path: *mut Object = msg_send![paths, firstObject];
let path: Id<NSString> = Id::from_ptr(msg_send![first_path, path]);
Some(path.as_str().to_string())
#[cfg(target_os="ios")]
pub fn default() -> Self{
use objc2::rc::Retained;
use objc2::msg_send;
use objc2_foundation::*;
let home_dir: Retained<NSString> = unsafe {NSHomeDirectory()};
let path = PathBuf::from(home_dir.to_string());
Self {
data_directory: Some(path.clone()),
cache_directory: Some(path.clone()),
}
}
}

View file

@ -1,4 +1,4 @@
pub mod global;
pub mod gui;
pub mod rpc;
pub mod server;
pub mod server;

View file

@ -6,6 +6,7 @@ use bevy::{
window::{AppLifecycle, ScreenEdge, WindowMode},
winit::WinitSettings,
};
use caretta_sync::config::PartialStorageConfig;
#[bevy_main]
pub fn main() {
@ -59,7 +60,7 @@ fn setup_scene(
}
))
.with_child((
Text::new(format!( "{:?}", std::fs::read_dir(std::env::current_dir().unwrap()).unwrap().map(|x| x.unwrap().path()).collect::<Vec<std::path::PathBuf>>())),
Text::new(format!("{:?}", PartialStorageConfig::default())),
TextFont {
font_size: 16.0,
..default()