@@ -35,31 +35,6 @@ pub const WEBVIEW_TARGET: &str = "webview";
3535
3636#[ cfg( target_os = "ios" ) ]
3737mod ios {
38- use cocoa:: base:: id;
39- use objc:: * ;
40-
41- const UTF8_ENCODING : usize = 4 ;
42- pub struct NSString ( pub id ) ;
43-
44- impl NSString {
45- pub fn new ( s : & str ) -> Self {
46- // Safety: objc runtime calls are unsafe
47- NSString ( unsafe {
48- let ns_string: id = msg_send ! [ class!( NSString ) , alloc] ;
49- let ns_string: id = msg_send ! [ ns_string,
50- initWithBytes: s. as_ptr( )
51- length: s. len( )
52- encoding: UTF8_ENCODING ] ;
53-
54- // The thing is allocated in rust, the thing must be set to autorelease in rust to relinquish control
55- // or it can not be released correctly in OC runtime
56- let _: ( ) = msg_send ! [ ns_string, autorelease] ;
57-
58- ns_string
59- } )
60- }
61- }
62-
6338 swift_rs:: swift!( pub fn tauri_log(
6439 level: u8 , message: * const std:: ffi:: c_void
6540 ) ) ;
@@ -429,7 +404,12 @@ impl Builder {
429404 log:: Level :: Info => 2 ,
430405 log:: Level :: Warn | log:: Level :: Error => 3 ,
431406 } ,
432- ios:: NSString :: new ( message. as_str ( ) ) . 0 as _ ,
407+ // The string is allocated in rust, so we must
408+ // autorelease it rust to give it to the Swift
409+ // runtime.
410+ objc2:: rc:: Retained :: autorelease_ptr (
411+ objc2_foundation:: NSString :: from_str ( message. as_str ( ) ) ,
412+ ) as _ ,
433413 ) ;
434414 }
435415 } ) ,
0 commit comments