From f84682e32633cee9c582fbc20fbe98cfa12f7d5c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 17 May 2023 05:18:28 +0300 Subject: Open links with in-app Safari --- Juick.xcodeproj/project.pbxproj | 4 ++++ Juick/ViewControllers/MessagesViewController.h | 3 ++- Juick/ViewControllers/MessagesViewController.m | 13 ++++++++++--- Juick/Views/MessageCell.swift | 7 ++++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 2f8fcb0..be77113 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ 778560632344CF6F00BB37A2 /* JuickNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 778560622344CF6F00BB37A2 /* JuickNavigationController.m */; }; 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77975A1C182B6E9A00410C2B /* NewPostViewController.m */; }; 77975A1F182BDCE900410C2B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77975A1E182BDCE900410C2B /* SystemConfiguration.framework */; }; + 779F82C72A146CE700D996D3 /* SafariServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 779F82C62A146CE600D996D3 /* SafariServices.framework */; }; 77A0954A181F1F25002BDECD /* Message.m in Sources */ = {isa = PBXBuildFile; fileRef = 77A09549181F1F25002BDECD /* Message.m */; }; 77B09994189D0B9900A84F59 /* UIImage+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B09993189D0B9900A84F59 /* UIImage+Utils.m */; }; 77B099A6189D57F000A84F59 /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B099A5189D57F000A84F59 /* User.m */; }; @@ -182,6 +183,7 @@ 77975A1C182B6E9A00410C2B /* NewPostViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewPostViewController.m; sourceTree = ""; }; 77975A1E182BDCE900410C2B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 77975A20182BDCF300410C2B /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; + 779F82C62A146CE600D996D3 /* SafariServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SafariServices.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/iOSSupport/System/Library/Frameworks/SafariServices.framework; sourceTree = DEVELOPER_DIR; }; 77A09548181F1F25002BDECD /* Message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Message.h; sourceTree = ""; }; 77A09549181F1F25002BDECD /* Message.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Message.m; sourceTree = ""; }; 77B09992189D0B9900A84F59 /* UIImage+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Utils.h"; sourceTree = ""; }; @@ -230,6 +232,7 @@ 77975A1F182BDCE900410C2B /* SystemConfiguration.framework in Frameworks */, 77C67EEC18283F2D00427098 /* QuartzCore.framework in Frameworks */, 77317BAE181BBE8500D60005 /* CoreGraphics.framework in Frameworks */, + 779F82C72A146CE700D996D3 /* SafariServices.framework in Frameworks */, 77317BB0181BBE8500D60005 /* UIKit.framework in Frameworks */, 77317BAC181BBE8500D60005 /* Foundation.framework in Frameworks */, 774746B6239F872A0001C7F9 /* CoreServices.framework in Frameworks */, @@ -298,6 +301,7 @@ 77317BAA181BBE8500D60005 /* Frameworks */ = { isa = PBXGroup; children = ( + 779F82C62A146CE600D996D3 /* SafariServices.framework */, 774746B5239F872A0001C7F9 /* CoreServices.framework */, 774528CB1F93EE9F004D110B /* libz.tbd */, 774528C91F93EE83004D110B /* AssetsLibrary.framework */, diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h index 55a2bde..d3e3f07 100644 --- a/Juick/ViewControllers/MessagesViewController.h +++ b/Juick/ViewControllers/MessagesViewController.h @@ -8,6 +8,7 @@ #import #import "Message.h" +@import SafariServices; @protocol MessageCellDelegate; @@ -17,7 +18,7 @@ extern NSString* const messageCellIdentifier; -(void) loadMore; @end -@interface MessagesViewController : UITableViewController +@interface MessagesViewController : UITableViewController @property(nonatomic, strong) NSString *path; @property(nonatomic, strong) NSDictionary *params; @property(nonatomic, assign) BOOL shouldScrollToUnreadOnRefresh; diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 8563fca..9fad013 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -226,11 +226,18 @@ NSString* const messageCellIdentifier = @"messageCell"; [self performSegueWithIdentifier:@"profileSegue" sender:self];*/ } +- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller { + [self dismissViewControllerAnimated:YES completion:nil]; +} + -(void)linkClicked:(NSString *)urlString { NSURL *url = [NSURL URLWithString:urlString]; - [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { - - }]; + SFSafariViewControllerConfiguration *configuration = [[SFSafariViewControllerConfiguration alloc] init]; + configuration.entersReaderIfAvailable = NO; + configuration.barCollapsingEnabled = YES; + SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url configuration:configuration]; + safariViewController.delegate = self; + [self presentViewController:safariViewController animated:YES completion:nil]; } - (void)dealloc diff --git a/Juick/Views/MessageCell.swift b/Juick/Views/MessageCell.swift index ebebec2..61867ce 100644 --- a/Juick/Views/MessageCell.swift +++ b/Juick/Views/MessageCell.swift @@ -14,7 +14,7 @@ import UIKit } @objc -class MessageCell: UITableViewCell { +class MessageCell: UITableViewCell, UITextViewDelegate { @IBOutlet weak var avatar: UIImageView! @IBOutlet weak var message: UITextView! @IBOutlet weak var title: UILabel! @@ -89,6 +89,7 @@ class MessageCell: UITableViewCell { } self.message.attributedText = nil if (msg.text != nil) { + self.message.delegate = self self.message.isHidden = false self.message.isSelectable = selectable self.message.isUserInteractionEnabled = selectable @@ -159,6 +160,10 @@ class MessageCell: UITableViewCell { self.delegate?.avatarClicked(name) } } + func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { + self.delegate?.linkClicked(URL.absoluteString) + return false + } @objc func linkClicked(_ sender: UITapGestureRecognizer){ self.delegate?.linkClicked(self.attachment!) } -- cgit v1.2.3