I have a UIWebView
. I am trying to implement ios11
drag and drop feature. When I drag item from Safari and drop it in my UIWebView
, I want to know which delegate method will get called. Any suggestions?
Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.
A simple working iOS RTCDataChannel built using WKWebView. Rather than include the external native WebRTC iOS framework at https://webrtc.org/native-code/ios, this library leverages WebKit's inbuilt WebRTC functionality and exposes WebRTC functionality through the WKWebView control.
As of iOS 12.0, 'UIWebView' has been explicitly marked as deprecated. Apple is encouraging developers to adopt WKWebView instead, which was introduced in iOS 8.0.
WKWebView - This view allows developers to embed web content in your app. You can think of WKWebView as a stripped-down version of Safari. It is responsible to load a URL request and display the web content. WKWebView has the benefit of the Nitro JavaScript engine and offers more features.
Most of the functionality of UIWebview is implemented in an undocumented class called UIWebBrowserView. It is that view which has its 'interactions' property set and the delegate for those interactions is set to that same UIWebBrowserView.
Depending on your needs, there are 3 options to detect the drop:
1) You could use javascript in the content of the web view to detect the drop. This would looks something like:
document.addEventListener('drop', function() {
// Drop detected
} ) ;
2) You could disable the drop interactions in the UIWebBrowserView. That will allow them to propagate up into one of the containing views, and you can add your own interactions there. That would look like:
webView.scrollView.subviews[0].interactions = @[] ;
Once you've done that, the you can create your own interactions and add them to the container view:
UIDropInteraction *dropInteration = [[UIDropInteraction alloc]initWithDelegate:myController] ;
[webView addInteraction:dropInteration] ;
webView.userInteractionEnabled = YES ;
You would then implement the UIDropInteractionDelegate functionality in 'myController'
3) You could swizzle UIWebBrowserView and replace the UIDropInteractionDelegate methods with your own.
UIDragInteractionDelegate & UIDropInteractionDelegate protocols are what you're looking for.
Check this out as well: How to Drop Images in UIViewController with UIDropInteraction (Ep 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With