iOS Question B4i code for w.a. chat

luke2012

Well-Known Member
Licensed User
Longtime User
Hi All,
within my B4i App I'm using this code to open a WhatsApp chat...


B4X:
'WA_URI is like this: "https://wa.me/393123456789"

If Main.App.CanOpenURL (WA_URI) Then
        Main.App.OpenURL(WA_URI)
End If

When I test it, WhatsApp is open and running but I got an error: "Safari cannot open the page because the address is invalid" but the w.a. url seem tp be correct : https://wa.me/<phone_number>.
 

aeric

Expert
Licensed User
Longtime User
Try:
B4X:
Dim NativeMe As NativeObject = Me
NativeMe.RunMethod("openScheme:", Array(WA_URI))

#If OBJC
- (void)openScheme:(NSString *)scheme {
       UIApplication *application = [UIApplication sharedApplication];
       NSURL *URL = [NSURL URLWithString:scheme];

       BOOL success = [application openURL:URL];
       NSLog(@"Open %@: %d",scheme,success);
           
       //if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
       //    [application openURL:URL options:@{}
       //    completionHandler:^(BOOL success) {
       //         NSLog(@"Open %@: %d",scheme,success);
       //     }];
       //  } else {
       //    BOOL success = [application openURL:URL];
       //    NSLog(@"Open %@: %d",scheme,success);
       //  }
     }
#End If
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User

Hi @aeric, first of all thanks for your reply but unfortunately same error screen: "Safari cannot open the page because the address is invalid", when executing exactly this line of code:

B4X:
NativeMe.RunMethod("openScheme:", Array(WA_URI))

The code within "#If OBJC" is skipped.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
How about trying to change it to following:
B4X:
WA_URI = "https://api.whatsapp.com/send/?phone=393123456789"

Hi @aeric, I tested it but unfortunately same error screen: "Safari cannot open the page because the address is invalid" :-(
Note: I'm testing it within a simulated iPhone. I'll do a test also on a real iPhone.

UPDATE: "Safari cannot open the page because the address is invalid" also on a real iPhone.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…