Make the user able to autopaste info in forms in UIWebView - iphone

After a few hours of googlening and testing I gave up the whole autofill a form in uiwebview and will now try another approch. However, I have no idea how to make it work.
All I really wanna do is to have two buttons, "username" and "password". The user will then highlight one of the forms textfields inside the webview and then press on of the buttons and the username will be printed in the textfield (if they pushed the username button that is).
So i want help with trying to understand how to control when they are highlighting a textfiled (ofc the keyboard will show up) and how i simulate a pastefunction.
Thank you

You can modify the content of an UIWebView injecting JavaScript, there are a few topics around here about that (edit: Also check this page).
In fact, you could automatically hand the the login/password directly through a javascript submit form action, instead of having to fill the visual form.
To get the contents of the Clipboard, use:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *pastedText = pasteboard.string;
(Note: The pasteboard is independent from your OS, meaning that if you copy something, it won't be recognized in the iphone app, you need to copy something from inside your iphone/simulator, the easiest way is to add a temporary UITextField, or go to the home screen, and get to the search page, and write there)

Related

UITextView Copy option not showing in top iPhone app?

Am working in message based iPhone app. I have added UITextView to show the messages typed by the user. This app allows the user to copy the messages. Whenever the user selects the messages in the bubbles the Copy option showing in middle of UITextView. How to show the Copy option in Top of the TextView?
Can anyone please help me to solve this issue? Thanks in advance.
Gopinath, this is in-built. You cannot change the default behavior. One option could be to write your own custom TextView which would show the copy option at the top. A workaround could be this:
Just let the user select the text (disable showing 'copy' in the UITextView)
You add a button at the top of the bubble
When the user selects the text & clicks on your UIButton 'copy', then copy whatever is the selection programmatically in your own method.

How would I go about detecting links in TTTAttributedLabel?

I have a table view and in some of the cells there are links, I want to be allow the user to click on these links and view them in a webView (which I have already made). I don't want to use the row selection event because there may be more than one link in the cell. I came across TTTAttributedLabel and think it will be ideal. I don't need to add any style to the text in the cell, I only need to detect the links and capture the click event to open up my webview.
Any help would be greatly appreciated.
It looks like you can assign a TTTAttributedLabelDelegate to a TTTAttributedLabel that will get call backs for when a user selects different link types, but no opportunity for you to capture them and open your own web view (which I think is what you're trying to accomplish).
Instead, you might wanna check out OHAttributedLabel. It's similar in functionality, but when a user clicks on one of the links in the label, it calls -(BOOL)attributedLabel:(OHAttributedLabel*)attributedLabel shouldFollowLink:(NSTextCheckingResult*)linkInfo on it's OHAttributedLabelDelegate, which gives you the opportunity to handle the link tap yourself if you return NO.

iphone - stuff inside alertview

I have a part on my app that I show the users, the files they have created and have stored inside the app's directory. I want to allow the users to rename the files.
I am wondering of doing this:
The user selects a file
The user taps on the RENAME button.
An alertview pops showing the old name and having a textview where the user can type the new name.
My question is: is this blessed by Apple? This sounds like a hack to the alertview.
Will the app be approved?
I googled around and I saw mixed opinions about that.
thanks
Generally I think the correct HIG-happy UI would be a UITableView with the list of of files. The user taps and Edit button and the page rows become editable, allowing you to delete a row/file (with a verification alert) and a disclosure arrow that pushes a detail view where you can change the name.
An alternative, though not HIG-friendly, is displaying the file name in a UITextField where the borderStyle set to UITextBorderStyleNone and the enabled set to NO. When the user taps the Rename button you change the borderStyle to UITextBorderStyleRoundedRect and enabled set to YES, setting the firstResponder to the text field so the cursor is flashing inside the textField. You'd need OK and Cancel buttons.
Or you could add a text field to the UIAlertView, also against the HIG but perhaps better.
I don't know if the property alertViewStyle was available when you make this question but searching to resolve this problem for me, I found that setting this property with UIAlertViewStylePlainTextInput resolve your problem.
Yes it is in iPhone sdk alertBox, alertBox can have the textField in which you rename the file.
check this link
for making such kind of stuff. No problem in accepting your app
You could either subclass UIAletView and add your own initWithTitle:message:...etc. method, as outlined in this tutorial, or use the undocumented [alert addTextFieldWithValue:#"" label:nil]; method, which is easier but may cause Apple to reject your app.

In the iOS SDK, how can I include a button in a UITextField like Mobile Safari does?

How can I display a button and/or activity indicator inside of a UITextField on the iPhone? I'm trying to reproduce Mobile Safari's location text field which contains either a reload button or a cancel (stop loading) button which is right-justified inside of the text field.
Similarly, when you click inside of the text field (not on the cancel/reload buttons) to edit the URL, a clear icon (x inside of a circle) is shown inside of the text field which will erase the contents of the text field.
How can I create this in my own apps? I cannot seem to do it via Interface Builder so I suspect it's being done in code.
There is a built in option that worked for me...check here:
Adding the "Clear" Button to an iPhone UITextField
Check out TTMessageController.

fill UIWebVIew TextInput with custom keyboard

For an app I am working on I want a custom keyboard to come up when you tap on an input field in a UIWebview, for example for UITextView i use this code :
myText.text = [myText.text stringByAppendingString:#"a"];
but i don't know how can i fill a text field in UIWebVIew
Any help would be very much appreciated; thanks!
I don't think it's possible to use a custom keyboard for a text field within a UIWebView.
There is bidirectional communication with the UIWebView, but it is a little convoluted.
You can use stringByEvaluatingJavaScriptFromString to execute any javascript in the context of the web page. That can be used to send data to the web page, modify forms, or poll for data and events.
You can use webView:shouldStartLoadWithRequest:navigationType: to receive notifications from the web view. Define a custom scheme like myapp: and handle all such requests returning NO from shouldStart. You can use ajax style calls to trigger the notifications, although the actual ajax call will always fail because you are returning NO.
If you want to have a custom keyboard show up, you must send a notification to the host application via your custom scheme, display a UITextView over the web view, then send the results back via javascript.
At least, that is the documented way to do it.
Check dcorbatta's answer in this article Custom Keyboard in UIWebView
He suggest to use a UITextField as a "media" when you detect keyboard coming up inside a UIWebView. Thus, you can use whatever Keyboard type you want on the UITextField. After users taps something, copy the text in UITextField the media via JavaScript ActiveDocument.
I spent too much time investigating that.
Blur the text inputs using JavaScript or jQuery.
Use on screen keyboard like any UIjquery plugin
Now you have to take a look at this nice keyboard and learn how to integrate it into you web pages.
http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/
One limitation.
It works only for your pages unless you hijack the page when it is done loading and attaché your keyboard and blur all text inputs when they get highlighted or focused.