views:

164

answers:

2

The question is pretty much in the title ;-)

Do you know if there is a webkit API for reading/writing from the iPhone keychain ? That is, I would need to access the keychain from a webapp.

Thanks in advance !

+1  A: 

I don't have an answer on how to do this straight from javascript, and unlike the Mac WebView, the UIWebView API doesn't let you expose arbitrary Objective C code as javascript functions.

However you can use a workaround that has a similar effect using the load delegate:

- (BOOL)webView:(UIWebView *)webView
    shouldStartLoadWithRequest:(NSURLRequest *)request
    navigationType:(UIWebViewNavigationType)navigationType
{
    if([[[request URL] scheme] isEqualToString:@"x-your-scheme"])
    {
        // parse the request and call the appropriate objc code here

        [webView stringByEvaluatingJavaScriptFromString:@"send(results);"];
        return NO;
    }

    return YES;
}

You trigger the load delegate by having your JS code load a "x-your-scheme://" URL.

duncanwilcox
+1  A: 

No, you can't.The keychain is only available from native apps. If you are using a UIWebView within a native app there are ways to bridge things around, but if it is a true web app with no native component it is not possible.

Louis Gerbarg