Skip to content

ios: Re-add nullability check for sharedApplication #99

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

Merged
merged 1 commit into from
Mar 10, 2025
Merged
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
16 changes: 14 additions & 2 deletions src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};

/// Returns `UIApplication`
#[allow(non_snake_case)]
fn sharedApplication(_mtm: MainThreadMarker) -> Retained<NSObject> {
fn sharedApplication(mtm: MainThreadMarker) -> Option<Retained<NSObject>> {
let _ = mtm;
// SAFETY: The signature is correct, and we hold `MainThreadMarker`, so we
// know we're on the main thread where it's safe to access the shared
// UIApplication.
//
// NOTE: `sharedApplication` is declared as returning non-NULL, but it
// will only do so inside `UIApplicationMain`; if called outside, the
// shared application is NULL.
unsafe { msg_send![class!(UIApplication), sharedApplication] }
}

Expand Down Expand Up @@ -46,7 +54,11 @@ pub(super) fn open_browser_internal(
ErrorKind::Other,
"UIApplication must be retrieved on the main thread",
))?;
let app = sharedApplication(mtm);

let app = sharedApplication(mtm).ok_or(Error::new(
ErrorKind::Other,
"UIApplication is NULL, perhaps UIApplicationMain has not been executed?",
))?;

// Create ns string class from our string
let url_string = NSString::from_str(url);
Expand Down