From d3033d2bb967a871918b46d496aefc9e681b4b75 Mon Sep 17 00:00:00 2001 From: YuigaWada Date: Tue, 14 Apr 2020 23:17:59 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=91=E3=83=BC=E3=83=AA?= =?UTF-8?q?=E3=83=B3=E3=82=AF=E3=81=8C=E6=AD=A3=E5=B8=B8=E3=81=AB=E5=8B=95?= =?UTF-8?q?=E4=BD=9C=E3=81=97=E3=81=AA=E3=81=84=E4=B8=8D=E5=85=B7=E5=90=88?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Others/Extension/UIViewController+MissCat.swift | 4 +++- MissCat/View/PostDetailViewController.swift | 13 +++++++++++-- MissCat/View/ProfileViewController.swift | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/MissCat/Others/Extension/UIViewController+MissCat.swift b/MissCat/Others/Extension/UIViewController+MissCat.swift index 9728fa7..3030be6 100644 --- a/MissCat/Others/Extension/UIViewController+MissCat.swift +++ b/MissCat/Others/Extension/UIViewController+MissCat.swift @@ -88,7 +88,9 @@ extension UIViewController { // MARK: Utilities func openLink(url: String) { - guard let url = URL(string: url), let rootVC = UIApplication.shared.windows[0].rootViewController else { return } + // URLをデコードしておく + guard let url = URL(string: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? url), + let rootVC = UIApplication.shared.windows[0].rootViewController else { return } let safari = SFSafariViewController(url: url) // i dont know why but it seems that we must launch a safari VC from the root VC. diff --git a/MissCat/View/PostDetailViewController.swift b/MissCat/View/PostDetailViewController.swift index d564933..35ad67e 100644 --- a/MissCat/View/PostDetailViewController.swift +++ b/MissCat/View/PostDetailViewController.swift @@ -156,8 +156,17 @@ class PostDetailViewController: NoteDisplay, UITableViewDelegate, FooterTabBarDe // MARK: Delegate override func tappedLink(text: String) { - navigationController?.popViewController(animated: true) - super.tappedLink(text: text) + let (linkType, value) = text.analyzeHyperLink() + switch linkType { + case .url: + homeViewController?.openLink(url: value) + case .user: + homeViewController?.move2Profile(userId: value) + case .hashtag: + navigationController?.popViewController(animated: true) + homeViewController?.emulateFooterTabTap(tab: .home) + homeViewController?.searchHashtag(tag: value) + } } func tappedNotifications() { diff --git a/MissCat/View/ProfileViewController.swift b/MissCat/View/ProfileViewController.swift index ec9f76e..e50cc35 100644 --- a/MissCat/View/ProfileViewController.swift +++ b/MissCat/View/ProfileViewController.swift @@ -295,15 +295,14 @@ class ProfileViewController: ButtonBarPagerTabStripViewController, UITextViewDel } func tappedLink(text: String) { - navigationController?.popViewController(animated: true) - let (linkType, value) = text.analyzeHyperLink() switch linkType { case .url: - homeViewController?.openUserPage(username: value) + homeViewController?.openLink(url: value) case .user: homeViewController?.move2Profile(userId: value) case .hashtag: + navigationController?.popViewController(animated: true) homeViewController?.emulateFooterTabTap(tab: .home) homeViewController?.searchHashtag(tag: value) }