@@ -555,7 +555,40 @@ pub fn create_delegate_class() {
555
555
YES
556
556
}
557
557
558
+ fn handle_deep_link ( url : id ) {
559
+ unsafe {
560
+ let absolute_url: id = msg_send ! [ url, absoluteString] ;
561
+ let bytes = {
562
+ let bytes: * const c_char = msg_send ! [ absolute_url, UTF8String ] ;
563
+ bytes as * const u8
564
+ } ;
565
+
566
+ // 4 represents utf8 encoding
567
+ let len = msg_send ! [ absolute_url, lengthOfBytesUsingEncoding: 4 ] ;
568
+ let bytes = std:: slice:: from_raw_parts ( bytes, len) ;
569
+
570
+ let url = url:: Url :: parse ( std:: str:: from_utf8 ( bytes) . unwrap ( ) ) . unwrap ( ) ;
571
+
572
+ app_state:: handle_nonuser_event ( EventWrapper :: StaticEvent ( Event :: Opened { urls : vec ! [ url] } ) ) ;
573
+ }
574
+ }
575
+
576
+ // custom URL schemes
577
+ // https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app
578
+ extern "C" fn application_open_url (
579
+ _self : & mut Object ,
580
+ _cmd : Sel ,
581
+ _app : id ,
582
+ url : id ,
583
+ _options : id ,
584
+ ) -> BOOL {
585
+ handle_deep_link ( url) ;
586
+
587
+ YES
588
+ }
589
+
558
590
// universal links
591
+ // https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app
559
592
extern "C" fn application_continue (
560
593
_: & mut Object ,
561
594
_: Sel ,
@@ -568,19 +601,8 @@ pub fn create_delegate_class() {
568
601
if webpage_url == nil {
569
602
return NO ;
570
603
}
571
- let absolute_url: id = msg_send ! [ webpage_url, absoluteString] ;
572
- let bytes = {
573
- let bytes: * const c_char = msg_send ! [ absolute_url, UTF8String ] ;
574
- bytes as * const u8
575
- } ;
576
604
577
- // 4 represents utf8 encoding
578
- let len = msg_send ! [ absolute_url, lengthOfBytesUsingEncoding: 4 ] ;
579
- let bytes = std:: slice:: from_raw_parts ( bytes, len) ;
580
-
581
- let url = url:: Url :: parse ( std:: str:: from_utf8 ( bytes) . unwrap ( ) ) . unwrap ( ) ;
582
-
583
- app_state:: handle_nonuser_event ( EventWrapper :: StaticEvent ( Event :: Opened { urls : vec ! [ url] } ) ) ;
605
+ handle_deep_link ( webpage_url) ;
584
606
585
607
YES
586
608
}
@@ -631,6 +653,11 @@ pub fn create_delegate_class() {
631
653
did_finish_launching as extern "C" fn ( & mut Object , Sel , id , id ) -> BOOL ,
632
654
) ;
633
655
656
+ decl. add_method (
657
+ sel ! ( application: openURL: options: ) ,
658
+ application_open_url as extern "C" fn ( & mut Object , Sel , id , id , id ) -> BOOL ,
659
+ ) ;
660
+
634
661
decl. add_method (
635
662
sel ! ( application: continueUserActivity: restorationHandler: ) ,
636
663
application_continue as extern "C" fn ( & mut Object , Sel , id , id , id ) -> BOOL ,
0 commit comments