Skip to content

Commit

Permalink
fix ios impl crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
extrawurst committed Apr 10, 2024
1 parent d924b7a commit 3bb4dad
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ pub(super) fn open_browser_internal(
"UIApplication is null, can't open url",
));
}
let url_cstr = std::ffi::CString::new(url).unwrap();

let url_cstr = std::ffi::CString::new(url)?;

// Create ns string class from our string
let url_string: *mut Object = msg_send![class!(NSString), stringWithUTF8String: url_cstr];
// Create NSURL object with given string
let url_object: *mut Object = msg_send![class!(NSURL), URLWithString: url_string];
// No completion handler
let null_ptr = std::ptr::null_mut::<Object>();
let nil: *mut Object = ::core::ptr::null_mut();
// empty options dictionary
let no_options: *mut Object = msg_send![class!(NSDictionary), new];

// Open url
let () = msg_send![app, openURL: url_object options: {} completionHandler: null_ptr];
let () = msg_send![app, openURL:url_object options:no_options completionHandler:nil];
Ok(())
}
}

0 comments on commit 3bb4dad

Please sign in to comment.