diff --git a/core/Cargo.toml b/core/Cargo.toml index c195326..d023696 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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" diff --git a/core/src/config/storage.rs b/core/src/config/storage.rs index 8cd8607..4792ede 100644 --- a/core/src/config/storage.rs +++ b/core/src/config/storage.rs @@ -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 = msg_send![file_manager, URLsForDirectory:1 inDomains:1]; - let first_path: *mut Object = msg_send![paths, firstObject]; - let path: Id = 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 = unsafe {NSHomeDirectory()}; + + let path = PathBuf::from(home_dir.to_string()); + Self { + data_directory: Some(path.clone()), + cache_directory: Some(path.clone()), } + + } } diff --git a/examples/core/src/lib.rs b/examples/core/src/lib.rs index 831b31d..2e6abba 100644 --- a/examples/core/src/lib.rs +++ b/examples/core/src/lib.rs @@ -1,4 +1,4 @@ pub mod global; pub mod gui; pub mod rpc; -pub mod server; +pub mod server; \ No newline at end of file diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index 4681831..655dd53 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -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::>())), + Text::new(format!("{:?}", PartialStorageConfig::default())), TextFont { font_size: 16.0, ..default()