Post

Replies

Boosts

Views

Activity

Why does NSURLSession with Multipath entitlement seamlessly switch to cellular when on a hardware Wi-Fi with no internet, but WKWebView does not?
Body:
Hi all, I’m seeing a puzzling discrepancy in behavior between NSURLSession (with multipathServiceType = NSURLSessionMultipathServiceTypeInteractive) and WKWebView when the device is connected to a Wi-Fi SSID that has no internet (e.g., a hardware device’s AP). I have the Multipath entitlement properly enabled, and in this scenario: NSURLSession requests automatically fall back to cellular and succeed (no user intervention, fast switch). WKWebView loads fail or stall: the web content does not appear, and it seems like the web view is not using the cellular path even though the system network path becomes satisfied and real Internet reachability is confirmed. Environment: iOS version: (e.g., iOS 18.4) Device: (e.g., iPhone 15 Pro) Multipath entitlement: enabled in the app, using NSURLSessionMultipathServiceTypeInteractive Connected SSID: hardware device Wi-Fi with no external internet Expected fallback: automatic to cellular once the Wi-Fi has no internet, as observed with NSURLSession What I’ve done / observed: NSURLSession using Multipath works as expected:
NSURLSessionConfiguration *cfg = [NSURLSessionConfiguration defaultSessionConfiguration];
cfg.multipathServiceType = NSURLSessionMultipathServiceTypeInteractive;
NSURLSession *session = [NSURLSession sessionWithConfiguration:cfg];
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.apple.com/library/test/success.html"]];
NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData *data, NSURLResponse *resp, NSError *err) {
NSLog(@"NSURLSession result: %@, error: %@", resp, err);
}];
[task resume];
When connected to the device Wi-Fi (no external internet), the session quietly shifts to cellular and completes successfully. WKWebView fails to load under the same conditions:
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.apple.com/library/test/success.html"]]];
The web view either shows a load failure or just hangs, even though lower-level monitoring reports that the network path is satisfied and real Internet connectivity is available. Network path monitoring logic: I use the C API nw_path_monitor to watch for nw_path_status_satisfied. Once satisfied is observed, I perform a true connectivity check using nw_connection (e.g., connecting tohttps://www.apple.com/library/test/success.html) to verify that real Internet traffic can flow over cellular. That check passes, confirming fallback to cellular, but WKWebView still does not load content. Meanwhile, NSURLSession requests in the same condition succeed immediately. Sample logging trace:
[+] nw_path_status_satisfied=1, hasWiFi=1, hasCellular=1
[+] Internet connectivity test: ready (via nw_connection)
[-] WKWebView load failed / stalled
[+] NSURLSession request completed successfully Questions: Why does NSURLSession with the multipath service type seamlessly use cellular when the Wi-Fi has no internet, but WKWebView does not exhibit the same fallback behavior? Is WKWebView not honoring the system’s multipath fallback the same way? Does it use a different networking stack or ignore the multipath entitlement in this scenario? Is there a supported way to force WKWebView to behave like NSURLSession here? For example, can I bridge content through a multipath-enabled NSURLSession and inject it into WKWebView via a custom scheme? Are there any WKWebView configuration flags, preferences, or policies that enable the same automatic interface switching? Are there known limitations or documented differences in how WKWebView handles network interface switching, path satisfaction, or multipath compared to raw NSURLSession? What I’ve ruled out / tried: Verified the Multipath entitlement is included and active. Confirmed network path is “satisfied” and that real Internet reachability succeeds before calling [webView loadRequest:]. Delayed the WKWebView load until after connectivity verification. Observed that NSURLSession requests succeed under identical connectivity conditions. Any insight into internal differences, recommended workarounds, or Apple-recommended patterns for making web content robust in a “Wi-Fi with no internet” + automatic fallback-to-cellular scenario would be greatly appreciated. Thank you!
1
0
109
Aug ’25
Why does NSURLSession with Multipath entitlement seamlessly switch to cellular when on a hardware Wi-Fi with no internet, but WKWebView does not?
正文:大家好, 当设备连接到没有互联网的 Wi-Fi SSID(例如,硬件设备的 AP)时,我看到 NSURLSession(multipathServiceType = NSURLSessionMultipathServiceTypeInteractive)和 WKWebView 之间的行为存在令人费解的差异。我正确启用了多路径授权,在这种情况下: NSURLSession 请求会自动回退到蜂窝网络并成功(无需用户干预,快速切换)。 WKWebView 加载失败或停滞:Web 内容未出现,即使系统网络路径得到满足并确认了真正的 Internet 可访问性,Web 视图似乎也没有使用蜂窝路径。 环境: iOS 版本:(例如 iOS 18.4) 设备:(例如 iPhone 15 Pro) 多路径权利:在应用程序中启用,使用 NSURLSessionMultipathServiceTypeInteractive 连接的 SSID:硬件设备 Wi-Fi,无需外部互联网 预期回退:一旦 Wi-Fi 没有互联网,就会自动到蜂窝网络,如 NSURLSession 所观察到的那样 我做了什么/观察到什么: 使用多路径的 NSURLSession 按预期工作:NSURLSessionConfiguration *cfg = [NSURLSessionConfiguration defaultSessionConfiguration];cfg.multipathServiceType = NSURLSessionMultipathServiceTypeInteractive;NSURLSession *session = [NSURLSession sessionWithConfiguration:cfg];NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@“https://www.apple.com/library/test/success.html”]];NSURLSessionDataTask *task = [session dataTaskWithRequest:req completionHandler:^(NSData *data, NSURLResponse *resp, NSError *err) { NSLog(@“NSURLSession result: %@, error: %@”, resp, err); }];[任务简历];连接到设备 Wi-Fi(无外部 Internet)时,会话会悄悄地切换到手机网络并成功完成。 相同情况下WKWebView加载失败:[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@“https://www.apple.com/library/test/success.html”]]];Web 视图要么显示负载失败,要么只是挂起,即使较低级别的监视报告网络路径已满足并且真正的 Internet 连接可用。 网络路径监控逻辑: 我使用 C API nw_path_monitor来监视nw_path_status_satisfied。 一旦观察到满意,我就会使用nw_connection(例如,连接 tohttps://www.apple.com/library/test/success.html)执行真正的连接检查,以验证真实的互联网流量是否可以通过蜂窝网络流动。 该检查通过,确认回退到手机网络,但 WKWebView 仍不会加载内容。同时,相同条件下的 NSURLSession 请求会立即成功。 示例日志记录跟踪:[+] nw_path_status_satisfied=1, hasWiFi=1, hasCellular=1 [+] Internet 连接测试:准备就绪(通过 nw_connection) [-] WKWebView 加载失败/停滞 [+] NSURLSession 请求成功完成 问题: 为什么当 Wi-Fi 没有 Internet 时,具有多路径服务类型的 NSURLSession 无缝使用蜂窝网络,但 WKWebView 不表现出相同的回退行为?WKWebView 是否不以相同的方式接受系统的多路径回退?在这种情况下,它是否使用不同的网络堆栈或忽略多路径授权? 是否有一种受支持的方法可以强制 WKWebView 像 NSURLSession 一样运行? 例如,我是否可以通过启用多路径的 NSURLSession 桥接内容,并通过自定义方案将其注入 WKWebView? 是否有任何 WKWebView 配置标志、首选项或策略启用相同的自动接口切换? 与原始 NSURLSession 相比,WKWebView 处理网络接换、路径满意度或多路径的方式是否存在已知限制或记录在案的差异? 我排除/尝试过的: 已验证多路径授权是否包含且处于活动状态。 确认的网络路径“满足”,并且在调用 [webView loadRequest:] 之前,真正的 Internet 可访问性成功。 将 WKWebView 加载延迟到连接验证之后。 观察到 NSURLSession 请求在相同的连接条件下成功。 任何对内部差异、推荐的解决方法或 Apple 推荐的模式的见解,以使 Web 内容在“没有互联网的 Wi-Fi”+ 自动回退到蜂窝场景中变得健壮,我们将不胜感激。 谢谢!
Topic: Safari & Web SubTopic: General
0
0
81
Aug ’25
Multipath
NSURLSessionConfiguration *cfg = [NSURLSessionConfiguration defaultSessionConfiguration]; cfg.allowsCellularAccess = YES; cfg.multipathServiceType = NSURLSessionMultipathServiceTypeInteractive; NSURLSession *session = [NSURLSession sessionWithConfiguration:cfg]; NSURL *url = [NSURL URLWithString:@"https://www.apple.com"]; [[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *resp, NSError *err) { if (err) { NSLog(@"❌ Request failed: %@", err); } else { NSLog(@"✅ Received %lu bytes via %@", (unsigned long)data.length, resp.URL.absoluteString); } }] resume]; When I use NSURLSession and set multipathServiceType = NSURLSessionMultipathServiceTypeInteractive, whenever I’m connected to a Wi‑Fi network without Internet access, all of my app’s network requests automatically and seamlessly fall back to cellular to fetch data. Why, then, can’t WKWebView load pages? What do I need to configure? Notes: My developer account already has the Multipath entitlement. I’ve added the Multipath capability under Signing & Capabilities in Xcode. In my .entitlements file I’ve set com.apple.developer.networking.multipath = true.
0
0
393
Jul ’25