Skip to content

Commit 31626de

Browse files
committed
ios: Upgrade to objc2 0.6 family of crates
This includes replacing manual bindings with the new `objc2-ui-kit` crate, getting rid of some manually-defined bindings.
1 parent 3ea6f97 commit 31626de

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ jni = "0.21"
3636
ndk-context = "0.1"
3737

3838
[target.'cfg(any(target_os = "ios", target_os = "tvos", target_os = "visionos"))'.dependencies]
39-
block2 = "0.5.0"
40-
objc2 = "0.5.1"
41-
objc2-foundation = { version = "0.2.0", default-features = false, features = [
39+
objc2 = "0.6"
40+
objc2-ui-kit = { version = "0.3", default-features = false, features = [
41+
"block2",
42+
"std",
43+
"UIApplication",
44+
"UIResponder",
45+
] }
46+
objc2-foundation = { version = "0.3", default-features = false, features = [
4247
"std",
4348
"NSDictionary",
4449
"NSString",

src/ios.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
2-
use block2::Block;
3-
use objc2::rc::Id;
4-
use objc2::runtime::Bool;
5-
use objc2::{class, msg_send, msg_send_id};
6-
use objc2_foundation::{NSDictionary, NSObject, NSString, NSURL};
7-
8-
fn app() -> Option<Id<NSObject>> {
9-
unsafe { msg_send_id![class!(UIApplication), sharedApplication] }
10-
}
11-
12-
fn open_url(
13-
app: &NSObject,
14-
url: &NSURL,
15-
options: &NSDictionary,
16-
handler: Option<&Block<dyn Fn(Bool)>>,
17-
) {
18-
unsafe { msg_send![app, openURL: url, options: options, completionHandler: handler] }
19-
}
2+
use objc2::MainThreadMarker;
3+
use objc2_foundation::{NSDictionary, NSString, NSURL};
4+
use objc2_ui_kit::UIApplication;
205

216
/// Deal with opening of browsers on iOS/tvOS/visionOS.
227
///
@@ -34,10 +19,11 @@ pub(super) fn open_browser_internal(
3419
return Ok(());
3520
}
3621

37-
let app = app().ok_or(Error::new(
22+
let mtm = MainThreadMarker::new().ok_or(Error::new(
3823
ErrorKind::Other,
39-
"UIApplication is null, can't open url",
24+
"UIApplication must be retrieved on main thread",
4025
))?;
26+
let app = UIApplication::sharedApplication(mtm);
4127

4228
// Create ns string class from our string
4329
let url_string = NSString::from_str(url);
@@ -50,6 +36,6 @@ pub(super) fn open_browser_internal(
5036
let options = NSDictionary::new();
5137

5238
// Open url
53-
open_url(&app, &url_object, &options, None);
39+
unsafe { app.openURL_options_completionHandler(&url_object, &options, None) };
5440
Ok(())
5541
}

0 commit comments

Comments
 (0)