开发者

Is there anyway to allow javascript without using a WebView on the iPhone?

I'm trying t开发者_开发知识库o make an app for a website (kind of like the facebook app). The problem is, logging in requires javascript to be enabled. I can't find anything in the documentation that refers to using javascript that isn't part of the UIWebView class.


The company I work for has the same. You are actually approaching this the wrong way. NSURLConnection allows you to pass all the information you need to the server ie username and password. Sometimes there will be additional parameters that get submitted using Javascript. What you have to do here is scan the necessary page for this variable name, grab the variable basically using a tokenizer, then send it back to the server using NSURLConnection POST/GET or part of he URL (or whatever way its being done). Let me know if you want more details on how I do it.

Here is the chunk of code that does the NSURLConnection with Javascript values:

if (postData) {
        [theRequest setHTTPMethod:HTTP_METHOD_POST];
        [theRequest setValue:FORM_ENCODING forHTTPHeaderField:@"Content-Type"];
        [theRequest setHTTPBody:postData];
    }
    if(cookies)
        [theRequest setAllHTTPHeaderFields:cookies];
    connection = [[NSURLConnection alloc] initWithRequest:theRequest  delegate:self  startImmediately:YES];

the postData in mine is in he form of a string like: "username=Rudigern&password=thePassword&JSVariable=somelongtoken"

This is of course specific to the site and getting somelongtoken is done by scanning the page for JSVariable. Some websites also require cookies as well as these variables and that is done by the cookie line. theRequest is of type NSURLMutableRequest.

This is how to look for the token:

[scanner scanUpToString:@"JSVariable=" intoString:somelongtoken];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜