Im trying to disable the long press on webKit to not let the user Save or Copy in Swift 4.
This is the code im using:
webView.stringByEvaluatingJavaScript(from: "document.body.style.webkitTouchCallout='none';")
I have seen some other answer in objective-c
[webView stringByEvaluatingJavaScriptFromString:#"document.body.style.webkitTouchCallout='none';"];
but converting it to swift it doesn't work.
Thanks in advance for any pointers.
There is a property called allowsLinkPreview with that you can enable or disable the long touch previews.
webView.allowsLinkPreview = false
Related
I enabled the dictation in my keyboard setting but still it's not working for iOS 10 for my developed application. While the AutoCorrection is working for my SMS APP.
Thanks in Adv.
You must not be adding the attribute for name NSTextAlternativesAttributeName back to attributed string and that's why suggestions are not coming. You will need to save the value of NSTextAlternativesAttributeName and add them again while you add your attributes.
That should solve the problem.
Also look at NSTextAlternatives
I've been developing a custom keyboard for iOS 8, but stumbled upon a problem trying to send images using the keyboard. I did some research and it seems like there isn't a simple way to do this with UITextDocumentProxy because only NSStrings are allowed.
Am I either overlooking any simple ways to use a custom keyboard to send images and/or is there any way to work around this issue?
Thanks in advance
Apparently, you are not the only person to try a keyboard like this. If you look at the animated GIF on the site, the keyboard uses copy/paste to add the image to the messages.
The UIKeyInput Protocol, which is inherited by UITextDocumentProxy, has the following function:
func insertText(_ text: String) //Swift
- (void)insertText:(NSString *)text //ObjC
These only take a String or an NSString, as you already know. Because there are no other methods to insert content, it can be assumed that, currently, there is no other way.
Right now, I would suggest that you adopt a similar usage. When the user taps on the image, add it to the UIPasteboard. Maybe present a little banner on top of the keyboard saying, "You can now paste" or something, but that would be up to you to decide.
I am new to iOS development. I want to perform a simple text to speech conversion within app.
Following is my code:
AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:#"Test text to speech conversion"];
[utterance setRate:1.1f];
[speechSynthesizer speakUtterance:utterance];
The above code is not giving me any exception but its not working at all. I've tried multiple APIs given on GitHub but nothing worked for me.
Could anybody tell me where I might be going wrong? Do I have to make any settings on device?
It's not working because of the Mute mode of your phone. To turn 'Mute On' in iOS 7, you have to follow the following steps:
Go to your Setting option
Go to Accessibility
Go to AssistiveTouch
Turn on AssistiveTouch option from the switch button
Then a Moving Assistive icon, will appear on you device screen.
Touch on it to expand with more options
From there select Device and Touch Un mute option.
Now run the project and hope it will work.
P.S: (In iOS 8.0 this code wouldn't work, because for an unexpected bug, from iOS8.1 they remove it and it is now working perfectly)
Hope it works. :)
Problem sorted..!! Actually the problem was, I had "USE SIDE SWITCH TO:" option in the Settings->General set to "Mute". I set that option to "Lock Rotation" and got rid of my problem. I found a related post here discussions.apple.com/thread/5366534
I'm currently developing some UIAutomation tests for an iOS App using KIF Framework. At some point, the app has to open a WebView with a login page, enter username and password and then press the sign-in button and all of these have to be automated.
My question is: knowing that at a certain moment in time the app displays that login page, how can i get the WebView UI element as in:
UIWebView *webView = // . . . ?
Also, it would be great if you could tell me how to get those two text fields (username and password), something like:
UITextField *textField = // ... ?
Thank you.
Use this code :
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.textContent"];
OR For all data
NSString *html = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.outerHTML"];
OR Check this link
I Hope this code useful for you.
the idea is that you want to kif to get hold of the webview after the webview has been loaded..
for that you will have to put the notifiying code in the webview delegate function webViewDidFinishLoad
in there.. you can put an NSNotification.. if you've used KIF for a while you know that you can instantiate actions only after you have recieved an NSNotification.. this is the the method in kif:
+ (id)stepToWaitForNotificationName:(NSString*)name object:(id)object;
as for finding the UIWebView itself, you just have to give it the same accessibility label you do with any other UIElement in iOS.
I'm just wondering how to disable the long press gesture on webview in iOS.
I need to disable only long press gesture not others.
should work on iOS 5.0 +
thank you
I want to thank all for help. I finally found the solution after intensive stackoverflow research. For help other :
In the javascript/html, you can avoid dealing with the longpress event.
The solution was given long time ago : Preventing default context menu on longpress / longclick in mobile Safari (iPad / iPhone)
I did it and it is just perfect. Thanks and thanks again.
JM
You could make UIWebView as a super class to one of your custom class, extend it.. and override touchesBegan.. methods from UIView class..