From 614a44d096fab6e3f1e47142d0fe0c1cd61d624d Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Thu, 3 Oct 2024 11:50:42 +0200 Subject: [PATCH] Fix external URL opening --- Classes/AboutView.m | 17 +++++------------ Classes/AssistantView.m | 9 +++------ Classes/LinphoneUI/UIConfirmationDialog.m | 4 +--- Classes/Swift/SwiftUtil.swift | 13 +++++++++++++ 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Classes/AboutView.m b/Classes/AboutView.m index 9329d01b3..2df16cba8 100644 --- a/Classes/AboutView.m +++ b/Classes/AboutView.m @@ -20,6 +20,7 @@ #import "PhoneMainView.h" #import "LinphoneManager.h" #import "LinphoneIOSVersion.h" +#import "linphoneapp-Swift.h" @implementation AboutView @@ -79,29 +80,21 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onLinkTap:(id)sender { UIGestureRecognizer *gest = sender; NSString *url = ((UILabel *)gest.view).text; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } - (IBAction)onPolicyTap { NSString *url = @"https://www.linphone.org/privacy-policy"; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } - (IBAction)onLicenceTap { NSString *url = @"https://www.gnu.org/licenses/gpl-3.0.html"; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } - (IBAction)onTranslateTap { NSString *url = @"https://weblate.linphone.org/projects/linphone-iphone"; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } - (IBAction)onDialerBackClick:(id)sender { diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index 9979fc071..9f8245f9b 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -29,6 +29,7 @@ #import "UITextField+DoneButton.h" #import "LinphoneAppDelegate.h" #import "SVProgressHUD.h" +#import "linphoneapp-Swift.h" #ifdef DEBUG #define PROVIDER_NAME "apns.dev" @@ -100,9 +101,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onContactTap { NSString *url = @"https://www.linphone.org/contact"; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"[Assistant] Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } - (void)viewDidLoad { @@ -1928,9 +1927,7 @@ UIColor *previousColor = (UIColor*)[sender backgroundColor]; \ - (IBAction)onLinkTap:(id)sender { NSString *url = @"https://subscribe.linphone.org"; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"[Assistant] Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } - (IBAction)onAcceptTermsClick:(id)sender { diff --git a/Classes/LinphoneUI/UIConfirmationDialog.m b/Classes/LinphoneUI/UIConfirmationDialog.m index 0abd0ecc4..0470b1e04 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.m +++ b/Classes/LinphoneUI/UIConfirmationDialog.m @@ -149,8 +149,6 @@ - (IBAction)onSubscribeTap:(id)sender { UIGestureRecognizer *gest = sender; NSString *url = ((UILabel *)gest.view).text; - if (![UIApplication.sharedApplication openURL:[NSURL URLWithString:url]]) { - LOGE(@"Failed to open %@, invalid URL", url); - } + [SwiftUtil openUrlWithUrlString:url]; } @end diff --git a/Classes/Swift/SwiftUtil.swift b/Classes/Swift/SwiftUtil.swift index 601685009..fe28f288c 100644 --- a/Classes/Swift/SwiftUtil.swift +++ b/Classes/Swift/SwiftUtil.swift @@ -121,5 +121,18 @@ import linphonesw return log.dir == .Incoming && [.Missed,.Aborted,.EarlyAborted].contains(log.status) } + @objc static func openUrl(urlString:String) { + if let url = URL(string: urlString) { + UIApplication.shared.open(url, options: [:], completionHandler: { success in + if (!success) { + Log.e("Unable to open URL \(urlString)") + } + }) + } else { + Log.e("Invalid URL \(urlString)") + } + + } + }