iPhone Web Application - objective-c

I had a quick question regarding UIWebView. Is there anyway to programmatically navigate the UIWebView? Essentially, I prompt the user for certain information, such as (Current Location, Time). Using this information, I would like to fill out and complete a form on a webpage, and display the resulting UIWebView to the user. Is this possible?

You could use JavaScript to control the UIWebView using the stringByEvaluatingJavaScriptFromString method. For example you should be able to insert text into an input and submit a form:
NSString* script = #"document.getElementById('Name').value = 'Hello'; document.getElementsByTagName('form')[0].submit();";
[self.web stringByEvaluatingJavaScriptFromString:script];
You'd have to customize the JavaScript to do whatever you want. For example, you could inject values that you had collected into the script, then run the JavaScript.
You could hide the UIWebView until the new page had loaded, then show it to the user.
Come to think of it, it'd be nice if there were a Selenium type wrapper around the web view, but I don't know of anything like that right now.

Related

Is it possible to track if a page finished loading with my current implementation of webView?

Picture of WebView
Hello, I am working on a login page for my app. Right now the webView login page works! However, there is one big issue with the current implementation.
Basically for my login I call a series of functions:
Opens hidden website with a webView,
Injects javaScript to login to website,
Changes to page of website containing data,
Extracts data,
Pushes to new view as login was successful
Now this is all working, except I had to hardcode times for each function to take place using DispatchQueue.main.async. This is of course problematic because some of the functions vary in time, for example the time it takes to load the webpage. This means my login is successful 75% of the time. I need a way to track if the webView is finished loading so I can call the next function only when it is done loading. However, every webView I have seen that has something like this, uses a completely different structure. When I have tried these other structures, I could not make certain things work like my login function that uses evaluateJavascript.
Is there anyway to have this feature by adding something to my current implementation? Thanks!

How to capture webform data from a WebView?

I'm building a Mac OS native application that uses a WebView to display custom data forms. The user will be able to fill out these forms to input data to the application. I need to be able to capture whatever data gets submitted as part of these html forms.
So if for example a webform comes up that has a text field which the user can use to enter a name - along with an 'OK' button next to it which submits the data - I would need to be able to capture whatever the user entered in that text field.
Keep in mind the HTML is loaded locally, not from a URL. Like so:
[[webview mainFrame] loadHTMLString:htmlSource baseURL:nil];
How can I capture any data that is being send entered this way?
This can easily be done in javascript, by intercepting the submit of your form and tracking the data. For this answer, I assume your webpage uses jQuery:
[webView stringByEvaluatingJavaScriptFromString:#" \
$('#yourForm').on('submit', function(e){ \
console.log(JSON.stringify($(this).serializeArray()));\
});"];
If you need this information in the Objective-C code, this thread describes how to bridge calls between javascript and Obj-C

Modifying photosphere on website thing

What i am trying to do is to use a photosphere on my website so that it shows up on full screen as a website cover page. The problem is the the code to embed a photosphere in a webpage given here by google
https://developers.google.com/photo-sphere/web/
lets only the photosphere size to be hardcoded as
displaysize="600,400"
what ever the values but its still hardcoded. What i want is that it gets adjusted to the screen of the user and gets displayed in the whole browser window. Any one got an idea how to pull it off? I didn't find any stuff about 'photosphere on web' other than the google link i gave above.
Indeed the API is currently designed to take static values. I think it's a good point that users might want to set the dimensions to 100% and let it resize dynamically.
I put it on the TODO list and will try to get to it shortly.
In the meantime, one work around is the following: After the viewer loads you will find an iframe on the page which contains it. You can change it's dimensions dynamically to your liking and the viewer should adapt.
The API provided by Google wraps the whole photosphere in layers of iFrames.
You can use the API to request a certain photosphere but only use the response to parse it for the values you need. Then you create your own request and the result can be shown fullscreen.
An example link is this
I created this link dynamically from the JSON response from the elements
media$group media$content 0 url
Hope it helps.
Can't you take the raw image and just use webgl to project it on the inside of a sphere?

Is there a way to programmatically click links, input info into login forms, etc in Objective-C? (like Mechanize does)

Is there anything similar to Mechanize for Objective-C? I want to enter info into a search bar, select a link, and then extract some information from the webpage
You can either run JavaScript code in the context of your WebView or interact with its DOM yourself.
You can inject javascript into the page to do what you want with stringByEvaluatingJavaScriptFromString. For example to simulate a click, inject:
getElementById('the_button').click();

How do I get a Captcha off a website and display it in a picturebox using VB.NET?

In Visual Basic .NET is there a way to access a website/signup page and then get the Captcha and load it into a picturebox? How would I do it?
From your question, I can't tell if you are looking for a captcha plug-in or use a plug-in from another site. If you're looking for a plugin, try Recaptcha.
UPDATE
Trying to pull a the captcha image off of a site could be done in two ways, but it the captcha rotation were done correctly, it would no do you any good to be able to pull it off.
One way would be to just right-click on the image and reference that URL in your code. However, as stated previously, this would not be that reliable. The service that generates the image would rotate, and the image URL would be different on every refresh. In other words, the copied URL would only be good for the one time you copied/captured it via right-click or whatever. If the URL did not rotate, then that would be a security issue for the site which is why the image source is different on each refresh.
Another way would be to make a direct request to the page, scrape the content for the captcha image's source, and pull the source from the parsed content. The code for this would be fairly specific per page, and, with my limited knowledge, I can't think of a way to make a generic application to do so.
I don't know why you would want to do what you are wanting to do, unless this is a homework assignment, or you are up to no good.
Depends on the captcha service the website uses.
If the site uses reCAPTCHA, you would probably need to look for the image tag that has id "recaptcha_challenge_image" and display that image tag in a web browser control.
Here is the demo page I found: http://www.google.com/recaptcha/demo/. If the captcha itself is in a frame (or iframe), you will need to check the code in the frame itself.