> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/webview-zhu-yi-shi-xiang/ios-webview-bu-huo-zhong-ding-xiang-url.md).

# iOS WebView (捕获重定向 URL)

由于 `WKWebView` 位于 iOS 系统级别，并且无法通过 API 直接访问或修改，因此受 iOS 的严格限制。为了捕获重定向 URL，建议使用以下方法：

```swift
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
    if navigationAction.targetFrame == nil {
        webView.load(navigationAction.request)
    }
    return nil
}
```

{% hint style="success" %} <mark style="color:green;">**解决方案说明**</mark>

1. **`navigationAction.targetFrame == nil`**：此条件判断确保了当目标框架不存在时（通常发生在页面重定向时），WebView 会加载新的请求，而不是默认的行为。
2. **避免窗口打开**：当 `targetFrame` 为 `nil` 时，WebView 会加载请求，避免弹出新窗口，确保重定向 URL 的正确捕获。

此方法有助于捕获并处理所有来自 WebView 的重定向请求。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/webview-zhu-yi-shi-xiang/ios-webview-bu-huo-zhong-ding-xiang-url.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
