Skip to content

Commit 0f4d885

Browse files
committed
ios: Re-add nullability check for sharedApplication
1 parent def4de1 commit 0f4d885

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/ios.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
77

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

@@ -46,7 +54,11 @@ pub(super) fn open_browser_internal(
4654
ErrorKind::Other,
4755
"UIApplication must be retrieved on the main thread",
4856
))?;
49-
let app = sharedApplication(mtm);
57+
58+
let app = sharedApplication(mtm).ok_or(Error::new(
59+
ErrorKind::Other,
60+
"UIApplication is NULL, perhaps UIApplicationMain has not been executed?",
61+
))?;
5062

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

0 commit comments

Comments
 (0)