Is there any way to hide the share option in Safari View Controller, which is coming by default?. I am trying to hide the extra options which are given by default with the Safari View Controller but not able to do so.
Let me know if anybody knows about this.
Thanks!
SFSafariViewController is not meant for customizations. Even Apple documentation says to use WKWebView if you want to customise the look and feel of safari view controller.
From Apple documentation
Choosing the Best Web Viewing Class
If your app lets users view websites from anywhere on the Internet,
use the SFSafariViewController class. If your app customizes,
interacts with, or controls the display of web content, use the
WKWebView class. When you adopt SFSafariViewController and a user
presses a link to peek at and then pop to the link’s destination, the
user views web content from within your app. Tapping Done, the user
returns to the view controller that was displayed before the web
content was loaded. When you instead use the WKWebView class, Peek and
Pop sends the user to Safari by default.
On the other hand, SFSafariViewController does provide some kind of UI customization. You can only change the preferredBarTintColor and prefererredControlTintColor. iOS 11 has new option to set initial configuration by using #NSCopying var configuration: SFSafariViewController.Configuration { get } but sadly that will not help you either
Related
let sfViewController = SFSafariViewController(url: url)
sfViewController.delegate = self
self.ViewC!.present(sfViewController, animated: false, completion: nil)
I am opening a SFSafariViewController in my app. But for the security issue I do not want the controls given by this view. This view is giving Actions like- Done, Refresh, Share, Open in Safari.
For My purpose I just want Action- Done. Rest other actions should not be visible to user. I am supporting ios 10.0 + .
Atleast that toolbar should not be there.
Is it possible to do this?
No, You Can't customize SFSafariViewController .
Apple says:
Important
In accordance with App Store Review Guidelines, this view controller
must be used to visibly present information to users; the controller
may not be hidden or obscured by other views or layers. Additionally,
an app may not use SFSafariViewController to track users without their
knowledge and consent.
Lastly, indeed, you may use WKWebView instead for further customisation of your screen.
If your app lets users view websites from anywhere on the Internet,
use the SFSafariViewController class. If your app customizes,
interacts with, or controls the display of web content, use the
WKWebView class.
Read doc: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
Is it possible customize SFSafariViewController like:
- change "Share" button
- or add new button on same toolbar where "Share" and "Compass" buttons are
Any help will be appreciated.
No. However, you can change some specific configuration of that controller. Namely:
through SFSafariViewControllerConfiguration, you have barCollapsingEnabled and entersReaderIfAvailable.
Data for activityItemsForURL and excludedActivityTypesForURL.
preferredBarTintColor and dismissButtonStyle, etc...
Apple says:
Important
In accordance with App Store Review Guidelines, this view controller
must be used to visibly present information to users; the controller
may not be hidden or obscured by other views or layers. Additionally,
an app may not use SFSafariViewController to track users without their
knowledge and consent.
Lastly, indeed, you may use WKWebView instead for further customisation of your screen.
If your app lets users view websites from anywhere on the Internet,
use the SFSafariViewController class. If your app customizes,
interacts with, or controls the display of web content, use the
WKWebView class.
Read doc: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
I want to build open-in like UI (see picture below).
It should include a list of icons representing actions and cancel button. I want pretty much UIAlertController only with icons (vs plain text).
Is there a standard iOS control which does something like or that or will I have to build/find a custom UI control for that?
From Apple's docs, each displayed service/action is a UIActivity, which is an abstract class, displayed in a UIActivityViewController which you can customize. There are several built-in services, and you can create your own w/custom icons. Yes, UIActionSheet was deprecated in iOS8.
The UIActivityViewController class is a standard view controller that
you can use to offer various services from your application. The
system provides several standard services, such as copying items to
the pasteboard, posting content to social media sites, sending items
via email or SMS, and more. Apps can also define custom services.
Your app is responsible for configuring, presenting, and dismissing
this view controller. Configuration for the view controller involves
specifying the data objects on which the view controller should act.
(You can also specify the list of custom services your app supports.)
When presenting the view controller, you must do so using the
appropriate means for the current device. On iPad, you must present
the view controller in a popover. On iPhone and iPod touch, you must
present it modally.
Also see this related question on some image gotchas ...
And this tutorial on adding a custom UIActivity to the view.
I just read some articles on UIActivityViewController and UIDocumentInteractionController in iOS, but I am very confused about how to use them because both seem the same.
So, when do I use UIActivityViewController or UIDocumentInteractionController?
Is there any difference for Open In... & use UIActivityViewController?
I am very confused about how to use them. Please clarify to me their specific use.
In short, UIDocumentInteractionController deals with files while UIActivityViewController deals with various other services in your app. I'm not one to criticize much but you really should at least try to google and read at least the overview in the iOS Developer Docs.
UIDocumentInteractionController documentation:
A view controller that previews, opens, or prints files whose file format cannot be handled directly by your app.
...
Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file. For example, an email program might use this class to allow the user to preview attachments and open them in other apps.
After presenting its user interface, a document interaction controller handles all interactions needed to support file preview and menu display.
You can also use the delegate to participate in interactions occurring within the presented interface. For example, the delegate is notified when a file is about to be handed off to another application for opening. For a complete description of the methods you can implement in your delegate, see UIDocumentInteractionControllerDelegate.
UIActivityViewController documentation:
A view controller that you use to offer standard services from your app.
...
The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.
Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
Basically UIActivityViewController shares Data Objects (like Strings or Images) where UIDocumentInteractionController shares whole Documents / Files f.e. a PDF.
I'm trying to create a UIActionSheet similar to Safari's. I haven't been able to find anything in the Apple documentation on how to make a UIActionSheet look like this. Is there a control/API that I am missing that I can use to create what's below, or am I stuck with creating my own UIView and displaying that?
Ninja Edit: This appears to be a UIActivityViewController. Is there any way I can add my own custom actions to it?
That is not a UIActionSheet.
It is a UIActivityViewController:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html
From Apple's Documentation:
The UIActivityViewController class is a standard view controller that you can use to offer
various services from your application. The system provides several standard services,
such as copying items to the pasteboard, posting content to social media sites, sending
items via email or SMS, and more. Apps can also define custom services.
Your app is responsible for configuring, presenting, and dismissing this view controller.
Configuration for the view controller involves specifying the data objects on which the
view controller should act. (You can also specify the list of custom services your app
supports.) When presenting the view controller, you must do so using the appropriate means
for the current device. On iPad, you must present the view controller in a popover. On
iPhone and iPod touch, you must present it modally.
About the ninja edit : Yes you can add actions to the UIActivityViewController.
See UIActivity on Apple's doc, or this SO question.