Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-126] iOS: Properly fetch device name from system #2788

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apps/mobile/modules/sd-core/ios/crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ crate-type = ["staticlib"]
[target.'cfg(target_os = "ios")'.dependencies]
# Spacedrive Sub-crates
sd-mobile-core = { path = "../../core" }
swift-rs = { version = "1.0", features = ["serde"] }

[target.'cfg(target_os = "ios")'.build-dependencies]
swift-rs = { version = "1.0", features = ["build"] }
16 changes: 16 additions & 0 deletions apps/mobile/modules/sd-core/ios/crate/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "SwiftRs",
"repositoryURL": "https://github.com/brendonovich/swift-rs",
"state": {
"branch": "specta",
"revision": "e0b4a5f444a4204efa8e8270468318bc7836fcce",
"version": null
}
}
]
},
"version": 1
}
35 changes: 35 additions & 0 deletions apps/mobile/modules/sd-core/ios/crate/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// swift-tools-version: 5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "sd-mobile-ios",
platforms: [
.iOS(.v14),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "sd-mobile-ios",
type: .static,
targets: ["sd-mobile-ios"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/brendonovich/swift-rs", branch: "specta"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "sd-mobile-ios",
dependencies: [
.product(name: "SwiftRs", package: "swift-rs")
],
path: "src-swift"
),
]
)

14 changes: 14 additions & 0 deletions apps/mobile/modules/sd-core/ios/crate/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[cfg(target_os = "ios")]
use std::env;

fn main() {
#[cfg(target_os = "ios")]
{
let deployment_target =
env::var("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or_else(|_| String::from("14.0"));

swift_rs::SwiftLinker::new(deployment_target.as_str())
.with_package("sd-mobile-ios", "./")
.link();
}
}
10 changes: 10 additions & 0 deletions apps/mobile/modules/sd-core/ios/crate/src-swift/device.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftRs
import UIKit

@_cdecl("fetch_device_name")
func fetchDeviceName() -> SRString {
// If we obtain the proper entitlement, this will return the device name -- otherwise,
// on iOS 16.0 or newer, it'll return the device model. -iLynxcat 26/oct/2024
// See: https://developer.apple.com/documentation/uikit/uidevice/1620015-name#discussion
return SRString(UIDevice.current.name)
}
3 changes: 3 additions & 0 deletions apps/mobile/modules/sd-core/ios/crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ pub unsafe extern "C" fn sd_core_msg(query: *const c_char, resolve: *const c_voi
println!("Error in sd_core_msg: {:?}", err);
}
}

use swift_rs::{swift, Bool, Int, SRData, SRObjectArray, SRString};
swift!(pub fn fetch_device_name() -> SRString);
Loading