开发者

Can I access keychain from a webapp (javascript) on the iPhone?

开发者 https://www.devze.com 2022-12-12 09:39 出处:网络
The question is pretty much in the title ;-) Do you know if the开发者_开发问答re is a webkit API for reading/writing from the iPhone keychain ? That is, I would need to access the keychain from a web

The question is pretty much in the title ;-)

Do you know if the开发者_开发问答re 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 !


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.


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.

0

精彩评论

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