<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MinPin Proxy</title>
    <description>The latest articles on DEV Community by MinPin Proxy (@minpin_proxy).</description>
    <link>https://dev.to/minpin_proxy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4241282%2F7f2d8c3e-147c-48c8-a56e-2c92a48175b3.png</url>
      <title>DEV Community: MinPin Proxy</title>
      <link>https://dev.to/minpin_proxy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/minpin_proxy"/>
    <language>en</language>
    <item>
      <title>The phone shows full Wi-Fi bars and every request fails. Captive portals and "connected" networks with no internet.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Thu, 03 Dec 2026 02:44:50 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-phone-shows-full-wi-fi-bars-and-every-request-fails-captive-portals-and-connected-networks-18hn</link>
      <guid>https://dev.to/minpin_proxy/the-phone-shows-full-wi-fi-bars-and-every-request-fails-captive-portals-and-connected-networks-18hn</guid>
      <description>&lt;p&gt;The bug reports come from hotels, airports, trains and offices: "The app says there's no internet, but I'm on Wi-Fi." Or the opposite: the app spins forever, then fails with a certificate error or a JSON parsing error. On the developer's home network none of it happens.&lt;/p&gt;

&lt;p&gt;The phone is connected to a network. That network just isn't giving it the internet, at least not yet. Here's what that looks like from the app's side and how to handle it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three kinds of "connected"
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A captive portal.&lt;/strong&gt; Hotel, airport and café Wi-Fi often block traffic until the user accepts terms or logs in on a web page. Until then, the network intercepts requests: plain HTTP gets a redirect or an HTML page, HTTPS usually fails, and DNS may answer with the portal's address for every name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wi-Fi with a dead uplink.&lt;/strong&gt; The router is up and hands out addresses, but its connection to the internet is down. Connections time out instead of being refused.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A network that blocks your hosts.&lt;/strong&gt; Corporate, school or public networks that filter by domain or port. Some hosts work, yours doesn't.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In all three, the operating system reports an active Wi-Fi interface, and a naive "are we online?" check says yes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the app actually sees
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS through a captive portal&lt;/strong&gt; typically fails during the TLS handshake. The portal can't present a valid certificate for your domain, so you see a certificate error (on iOS, codes like &lt;code&gt;-1202&lt;/code&gt; or &lt;code&gt;-1200&lt;/code&gt;; on Android, an &lt;code&gt;SSLHandshakeException&lt;/code&gt;) or a timeout. To the user it looks like your server is broken.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plain HTTP through a captive portal&lt;/strong&gt; can come back as &lt;code&gt;200 OK&lt;/code&gt; with the portal's HTML, or as a &lt;code&gt;302&lt;/code&gt; to the login page that the client follows. If the app decodes the body as JSON, the error is about an unexpected &lt;code&gt;&amp;lt;&lt;/code&gt;, not about the network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A dead uplink&lt;/strong&gt; gives connection or DNS timeouts, which can take as long as your timeout settings allow. With default settings that can be a minute or more before the user sees anything.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the OS knows (and what it doesn't)
&lt;/h2&gt;

&lt;p&gt;Both platforms check connectivity themselves when a network is joined, and both expose some of that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Android&lt;/strong&gt;: &lt;code&gt;NetworkCapabilities&lt;/code&gt; has &lt;code&gt;NET_CAPABILITY_INTERNET&lt;/code&gt; (the network says it should provide internet) and &lt;code&gt;NET_CAPABILITY_VALIDATED&lt;/code&gt; (the system actually reached its test server through it). A captive network may also carry &lt;code&gt;NET_CAPABILITY_CAPTIVE_PORTAL&lt;/code&gt;. &lt;code&gt;INTERNET&lt;/code&gt; alone doesn't mean it works; &lt;code&gt;VALIDATED&lt;/code&gt; is the closer signal. Register a callback with &lt;code&gt;ConnectivityManager&lt;/code&gt; to hear when it changes, rather than checking once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt;: &lt;code&gt;NWPathMonitor&lt;/code&gt; reports a path as &lt;code&gt;.satisfied&lt;/code&gt; when there's a usable route, which doesn't guarantee your server is reachable. The system usually shows its own sign-in sheet when it detects a captive portal on joining Wi-Fi, but if the user dismisses it, the device can stay on that network with no real internet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apple's guidance has long been not to preflight a request with a reachability check: try the request, and handle the failure. A check can be wrong in both directions, and it adds a delay to every request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handling it in the app
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Classify the failure before you show it.&lt;/strong&gt; A certificate error on a host that works for everyone else, or an HTML body where you expected JSON, points to the network, not your server. Show "This Wi-Fi network may need you to sign in, or try mobile data" instead of a generic error or "Our servers are down".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the &lt;code&gt;Content-Type&lt;/code&gt; before decoding.&lt;/strong&gt; If it's &lt;code&gt;text/html&lt;/code&gt; on a JSON endpoint, report that as a network problem with the status code and final URL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't wait for the full timeout when you don't have to.&lt;/strong&gt; On iOS, &lt;code&gt;waitsForConnectivity&lt;/code&gt; on the session configuration lets a request wait for a usable path instead of failing at once; pair it with a sensible &lt;code&gt;timeoutIntervalForResource&lt;/code&gt; so it doesn't wait for the 7-day default. On Android, reacting to the network callback (for example retrying when a network becomes &lt;code&gt;VALIDATED&lt;/code&gt;) avoids polling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retry when the network changes, not on a timer.&lt;/strong&gt; When the user signs in to the portal or switches to mobile data, the OS reports a network change. That's the moment to retry, once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Low Data Mode and metered settings are a separate case.&lt;/strong&gt; On iOS, if a request sets &lt;code&gt;allowsConstrainedNetworkAccess = false&lt;/code&gt; and the user has Low Data Mode on, the request fails with a "not connected" error even though the network works. Check the error's &lt;code&gt;networkUnavailableReason&lt;/code&gt; before telling the user they're offline.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fake a captive portal with a proxy or local server rule&lt;/strong&gt;: answer every request to your API with &lt;code&gt;302&lt;/code&gt; to an HTML page, or &lt;code&gt;200&lt;/code&gt; with an HTML body. Check that the app shows a network message, not a decoding crash.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fake a dead uplink&lt;/strong&gt;: a hotspot or travel router with its WAN cable unplugged, or a network conditioner profile with 100% packet loss. Measure how long the app takes to show an error and whether the UI stays usable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test the transition&lt;/strong&gt;: start on the "dead" network, then fix it (plug the cable back in, or switch to mobile data) and check that the app recovers without being restarted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look at the real thing when you can.&lt;/strong&gt; Connect a test phone to a public Wi-Fi network, don't accept the portal, open the app, and watch the requests it sends and the responses it gets.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>mobile</category>
      <category>android</category>
      <category>networking</category>
      <category>ios</category>
    </item>
    <item>
      <title>The backend added one enum value and last year's app version started crashing. Shipping API changes to apps you can't update.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Wed, 02 Dec 2026 02:44:38 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-backend-added-one-enum-value-and-last-years-app-version-started-crashing-shipping-api-changes-243e</link>
      <guid>https://dev.to/minpin_proxy/the-backend-added-one-enum-value-and-last-years-app-version-started-crashing-shipping-api-changes-243e</guid>
      <description>&lt;p&gt;The backend team made what looked like a safe change: a new order status, &lt;code&gt;"partially_refunded"&lt;/code&gt;. The web app picked it up the same day. The current mobile release handled it fine. But a version from eight months ago, still on a few percent of devices, started failing to load the order list for anyone who had one of those orders. The API hadn't removed or renamed anything.&lt;/p&gt;

&lt;p&gt;A web frontend updates the moment you deploy it. A mobile app doesn't. Old versions stay installed for months or years, and they parse your responses with whatever rules they were built with. Here's what usually breaks them and how to change an API without finding out from crash reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks old clients
&lt;/h2&gt;

&lt;p&gt;Most of these come from the JSON decoder, not your own code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A new enum value.&lt;/strong&gt; Swift's &lt;code&gt;Codable&lt;/code&gt; throws when a raw value isn't one of the enum's cases. Moshi throws on unknown enum values by default too. Gson tends to set the field to &lt;code&gt;null&lt;/code&gt; instead, which in Kotlin can put a &lt;code&gt;null&lt;/code&gt; into a property declared non-null and fail later, somewhere unrelated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A field that becomes &lt;code&gt;null&lt;/code&gt; or goes missing.&lt;/strong&gt; If the model declares it non-optional, decoding fails with an error like &lt;code&gt;keyNotFound&lt;/code&gt; or &lt;code&gt;valueNotFound&lt;/code&gt; in Swift, or a missing-field exception in kotlinx.serialization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A changed type.&lt;/strong&gt; An &lt;code&gt;id&lt;/code&gt; that was a number and is now a string, or a price that moves from a number to an object. Old decoders fail with a type mismatch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One bad item fails the whole list.&lt;/strong&gt; With a plain &lt;code&gt;[Order]&lt;/code&gt; or &lt;code&gt;List&amp;lt;Order&amp;gt;&lt;/code&gt;, one order the old model can't decode usually fails the entire response, so the user sees an empty or error screen, not one missing row. That's why only users with a "partially refunded" order were affected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New keys, depending on the library.&lt;/strong&gt; Swift's &lt;code&gt;Codable&lt;/code&gt;, Moshi and Gson ignore keys they don't know. kotlinx.serialization does not by default: unless &lt;code&gt;ignoreUnknownKeys = true&lt;/code&gt; is set, any new field in a response throws. This one catches teams that switched libraries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Make the client tolerant
&lt;/h2&gt;

&lt;p&gt;Changes in the app protect future versions, so do them before you need them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unknown enum values map to a fallback.&lt;/strong&gt; In Swift, decode the raw string and fall back to an &lt;code&gt;.unknown&lt;/code&gt; case in a custom &lt;code&gt;init(from:)&lt;/code&gt;. In Moshi, &lt;code&gt;EnumJsonAdapter.create(...).withUnknownFallback(...)&lt;/code&gt; from &lt;code&gt;moshi-adapters&lt;/code&gt;. In kotlinx.serialization, &lt;code&gt;coerceInputValues = true&lt;/code&gt; can replace an unknown enum value with the property's default, if it has one (check the behavior for your version). Then make the UI show something neutral for &lt;code&gt;.unknown&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignore unknown keys&lt;/strong&gt; everywhere. For kotlinx.serialization, set &lt;code&gt;ignoreUnknownKeys = true&lt;/code&gt; on the shared &lt;code&gt;Json&lt;/code&gt; instance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decode lists item by item&lt;/strong&gt; where one bad item shouldn't hide the rest: decode each element separately, drop (and log) the ones that fail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make fields optional&lt;/strong&gt; when the app can work without them, and give defaults rather than crashing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log decoding failures with the endpoint and field path&lt;/strong&gt; so a schema problem shows up as a clear report, not a generic "something went wrong".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Make the server careful
&lt;/h2&gt;

&lt;p&gt;The server can't fix installed apps, so it has to change in ways old apps survive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Add, don't change.&lt;/strong&gt; New fields are usually safe. Renaming, removing or changing the type of a field is a breaking change for every old version that reads it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know which versions are still calling.&lt;/strong&gt; Send the app version and build number on every request (in the &lt;code&gt;User-Agent&lt;/code&gt; or a dedicated header) and log it. Before removing a field or changing an enum, check how much traffic still comes from versions that depend on it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version per client when needed.&lt;/strong&gt; If a change can't be additive, serve the old shape to old versions (based on that header, or a versioned path) until their share is small enough to drop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gate new enum values.&lt;/strong&gt; A new status can be sent only to app versions that know it, with older versions getting the closest existing value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A way to force an update
&lt;/h2&gt;

&lt;p&gt;At some point the oldest versions have to go. Plan for it before you need it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A minimum-version check&lt;/strong&gt;: the app asks a config endpoint (or reads a header on every response) for the minimum supported version, and shows a blocking "please update" screen below it. This has to be in the app already. You can't add it to versions that are installed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On Android&lt;/strong&gt;, the Play In-App Updates API can show an immediate or flexible update flow. &lt;strong&gt;On iOS&lt;/strong&gt; there's no built-in equivalent, so most apps show their own screen with a link to the App Store page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use it rarely.&lt;/strong&gt; A forced update annoys users and doesn't help people with no connection or an old OS the new version doesn't support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Decoder tests with hostile JSON:&lt;/strong&gt; an extra key, an unknown enum value, a &lt;code&gt;null&lt;/code&gt; in each field, and a list where one item is malformed. Each should produce a usable result, not a thrown error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run an old build against staging&lt;/strong&gt; before shipping a backend change. Keep the last few release builds installable for this.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replay recorded responses.&lt;/strong&gt; Save real responses from the current API and decode them with the models from older releases in CI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch the response, not just the code.&lt;/strong&gt; Before a schema change, capture what the server actually sends today. Fields the docs say are never &lt;code&gt;null&lt;/code&gt; sometimes are.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>api</category>
      <category>mobile</category>
    </item>
    <item>
      <title>The POST arrived as a GET, without its auth header. Redirects your HTTP client follows without telling you.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Tue, 01 Dec 2026 02:45:01 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-post-arrived-as-a-get-without-its-auth-header-redirects-your-http-client-follows-without-4k06</link>
      <guid>https://dev.to/minpin_proxy/the-post-arrived-as-a-get-without-its-auth-header-redirects-your-http-client-follows-without-4k06</guid>
      <description>&lt;p&gt;The bug report: the endpoint works in the API docs' "try it" page, works in curl, and from the app the server logs show a &lt;code&gt;GET&lt;/code&gt; with no body where the app sent a &lt;code&gt;POST&lt;/code&gt;. Or the request arrives without its &lt;code&gt;Authorization&lt;/code&gt; header and gets a &lt;code&gt;401&lt;/code&gt;. Or the app crashes decoding JSON because the "response" starts with &lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The app's code never mentions a redirect. That's the problem: URLSession and OkHttp follow redirects by default, so the request your code built and the request that reached the final server can be different. Here's what changes on the way and how to see it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a redirect does to your request
&lt;/h2&gt;

&lt;p&gt;The status code decides what happens to the method and the body:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;301&lt;/code&gt; and &lt;code&gt;302&lt;/code&gt;&lt;/strong&gt;: the spec allows clients to change &lt;code&gt;POST&lt;/code&gt; to &lt;code&gt;GET&lt;/code&gt; for historical reasons, and in practice many clients do. OkHttp, for example, switches to &lt;code&gt;GET&lt;/code&gt; and drops the body for &lt;code&gt;301&lt;/code&gt;, &lt;code&gt;302&lt;/code&gt; and &lt;code&gt;303&lt;/code&gt;. URLSession is generally reported to behave the same way for &lt;code&gt;POST&lt;/code&gt;. Either way, your JSON body is gone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;303 See Other&lt;/code&gt;&lt;/strong&gt;: always means "fetch the result with &lt;code&gt;GET&lt;/code&gt;".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;307&lt;/code&gt; and &lt;code&gt;308&lt;/code&gt;&lt;/strong&gt;: the method and body must be kept. If a server needs a redirect for an API endpoint, these are the codes to use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Headers change too:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Authorization&lt;/code&gt; can be removed&lt;/strong&gt; when the redirect goes to a different host. OkHttp does this on purpose, so a token isn't sent to a server it wasn't meant for. If your API redirects &lt;code&gt;api.example.com&lt;/code&gt; to &lt;code&gt;api2.example.com&lt;/code&gt;, the second request arrives unauthenticated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom headers&lt;/strong&gt; are generally kept by OkHttp and URLSession when following a redirect, but behavior differs between libraries and versions, so check rather than assume.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where the redirects come from
&lt;/h2&gt;

&lt;p&gt;Most of them aren't intentional API design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTP to HTTPS.&lt;/strong&gt; A load balancer redirects &lt;code&gt;http://&lt;/code&gt; to &lt;code&gt;https://&lt;/code&gt; with a &lt;code&gt;301&lt;/code&gt;. Any &lt;code&gt;POST&lt;/code&gt; to the &lt;code&gt;http&lt;/code&gt; URL becomes a &lt;code&gt;GET&lt;/code&gt; on the way. On iOS, App Transport Security usually blocks the plain-HTTP request first. On Android, cleartext traffic is blocked by default for apps targeting Android 9 (API 28) or higher, unless the network security config allows it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trailing slashes.&lt;/strong&gt; Some frameworks redirect &lt;code&gt;/api/items&lt;/code&gt; to &lt;code&gt;/api/items/&lt;/code&gt; (or the reverse) with a &lt;code&gt;301&lt;/code&gt;. The app's &lt;code&gt;POST /api/items&lt;/code&gt; becomes &lt;code&gt;GET /api/items/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain changes.&lt;/strong&gt; &lt;code&gt;example.com&lt;/code&gt; to &lt;code&gt;www.example.com&lt;/code&gt;, or an old API host to a new one. Method changes and stripped &lt;code&gt;Authorization&lt;/code&gt; headers both show up here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expired sessions.&lt;/strong&gt; A gateway or web framework answers an unauthenticated API call with &lt;code&gt;302&lt;/code&gt; to a login page. The client follows it, gets &lt;code&gt;200&lt;/code&gt; with HTML, and the JSON decoder fails with an error about an unexpected &lt;code&gt;&amp;lt;&lt;/code&gt;. The real problem was an expired token, but the error points at parsing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to see the redirect chain
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;curl&lt;/strong&gt;: &lt;code&gt;curl -v&lt;/code&gt; shows the &lt;code&gt;3xx&lt;/code&gt; and the &lt;code&gt;Location&lt;/code&gt; header without following it. &lt;code&gt;curl -L -v&lt;/code&gt; follows and prints every hop. Note that curl itself changes &lt;code&gt;POST&lt;/code&gt; to &lt;code&gt;GET&lt;/code&gt; on &lt;code&gt;301&lt;/code&gt;/&lt;code&gt;302&lt;/code&gt;/&lt;code&gt;303&lt;/code&gt; unless told otherwise (&lt;code&gt;--post301&lt;/code&gt;, &lt;code&gt;--post302&lt;/code&gt;), so it's a fair stand-in for a mobile client.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt;: implement &lt;code&gt;urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)&lt;/code&gt; on the session delegate. Log the response status, the old URL, and the new request's method and headers. Passing &lt;code&gt;nil&lt;/code&gt; to the completion handler stops following, and your code receives the &lt;code&gt;3xx&lt;/code&gt; itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Android (OkHttp)&lt;/strong&gt;: a network interceptor (&lt;code&gt;addNetworkInterceptor&lt;/code&gt;) sees every hop, including each redirect response, while an application interceptor only sees the final result. For debugging, &lt;code&gt;followRedirects(false)&lt;/code&gt; makes the &lt;code&gt;3xx&lt;/code&gt; visible to your code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A debugging proxy or network inspector&lt;/strong&gt; shows each hop as a separate request, which makes the method change and the missing header obvious side by side.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fixing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Call the final URL.&lt;/strong&gt; In the app's config, use the &lt;code&gt;https&lt;/code&gt; URL with the exact path the server expects, trailing slash included. A redirect on every request also costs an extra round trip.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;307&lt;/code&gt;/&lt;code&gt;308&lt;/code&gt; on the server&lt;/strong&gt; when an API endpoint really moves, so method and body survive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return &lt;code&gt;401&lt;/code&gt; to API clients, not &lt;code&gt;302&lt;/code&gt;.&lt;/strong&gt; If the backend shares middleware with a web app, make sure API routes (or requests with &lt;code&gt;Accept: application/json&lt;/code&gt;) get a &lt;code&gt;401&lt;/code&gt; with a JSON body instead of a redirect to a login page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treat an HTML response as an error.&lt;/strong&gt; Check the &lt;code&gt;Content-Type&lt;/code&gt; before decoding, and report "unexpected HTML response" with the status and final URL instead of a decoder error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-add auth deliberately, if at all.&lt;/strong&gt; If a cross-host redirect is expected, an OkHttp &lt;code&gt;Authenticator&lt;/code&gt; or the URLSession redirect delegate can attach credentials for hosts you trust. Don't re-add a token for any host a &lt;code&gt;Location&lt;/code&gt; header names.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Point a debug build at the &lt;code&gt;http://&lt;/code&gt; URL of each API host and confirm what happens: blocked, or redirected with the method intact.&lt;/li&gt;
&lt;li&gt;Call a path with and without a trailing slash and check the server's response code.&lt;/li&gt;
&lt;li&gt;Expire a token on purpose and check that the app gets a &lt;code&gt;401&lt;/code&gt; it can handle, not an HTML page.&lt;/li&gt;
&lt;li&gt;In the proxy or interceptor logs, look for any &lt;code&gt;3xx&lt;/code&gt; in normal traffic. Each one is either a wasted round trip or a request that changed on the way.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>api</category>
      <category>debugging</category>
    </item>
    <item>
      <title>It works for everyone except one user, and their phone's clock is wrong. Time bugs in mobile HTTP.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Mon, 30 Nov 2026 02:45:28 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/it-works-for-everyone-except-one-user-and-their-phones-clock-is-wrong-time-bugs-in-mobile-http-2k69</link>
      <guid>https://dev.to/minpin_proxy/it-works-for-everyone-except-one-user-and-their-phones-clock-is-wrong-time-bugs-in-mobile-http-2k69</guid>
      <description>&lt;p&gt;The support ticket: one user can't log in, or every request fails with a TLS error, or their uploads are rejected with "request expired". Nobody else has the problem. The logs show nothing useful. After a long call it turns out the phone's date is set by hand, a few hours or a few years off.&lt;/p&gt;

&lt;p&gt;Phones are usually right about the time, because they sync it from the network. But "usually" covers a lot of users: people who turned off automatic time to cheat a game timer, devices that booted without a network, test phones that sat in a drawer, and anyone who changed the time zone by hand instead of the time. Here's what breaks, and how to make the app tolerate it.&lt;/p&gt;

&lt;h2&gt;
  
  
  TLS fails before your code runs
&lt;/h2&gt;

&lt;p&gt;Certificate validation checks the current date against the certificate's validity period. If the device thinks it's 2019, a certificate issued last month is "not yet valid". If it thinks it's 2031, the certificate has expired.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt; reports it as &lt;code&gt;NSURLErrorServerCertificateNotYetValid&lt;/code&gt; (&lt;code&gt;-1204&lt;/code&gt;) or &lt;code&gt;NSURLErrorServerCertificateHasBadDate&lt;/code&gt; (&lt;code&gt;-1201&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Android&lt;/strong&gt; usually shows an &lt;code&gt;SSLHandshakeException&lt;/code&gt;, with a cause that mentions the certificate not being valid yet or having expired, depending on the device and library.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To the user it looks like "no internet". If your error handling turns every networking error into "Check your connection", map these specific errors to a message that says the device's date and time look wrong. It's one of the few TLS errors the user can fix themselves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tokens that expire "early" or never
&lt;/h2&gt;

&lt;p&gt;Access tokens (often JWTs) carry times: &lt;code&gt;iat&lt;/code&gt; (issued at), &lt;code&gt;nbf&lt;/code&gt; (not before), &lt;code&gt;exp&lt;/code&gt; (expires).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;On the server&lt;/strong&gt;, the clock is right, but a strict check with no leeway can reject a token whose &lt;code&gt;nbf&lt;/code&gt; is a second ahead because of skew between your own servers. A small leeway (often 30 to 60 seconds is used) is normal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On the client&lt;/strong&gt;, reading &lt;code&gt;exp&lt;/code&gt; and comparing it with the device clock is where it goes wrong. A phone that's an hour fast thinks every new token has already expired and refreshes in a loop. A phone that's slow keeps sending expired tokens and relies on the &lt;code&gt;401&lt;/code&gt; to recover.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Safer: don't trust the device clock for expiry decisions. Either use the &lt;code&gt;expires_in&lt;/code&gt; value from the token response and count it down with a monotonic clock, or treat the server's &lt;code&gt;401&lt;/code&gt; as the real signal and refresh then (once, not in a loop).&lt;/p&gt;

&lt;h2&gt;
  
  
  Signed requests and expiring URLs
&lt;/h2&gt;

&lt;p&gt;Anything signed with a timestamp is checked against the server's clock:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Request signing&lt;/strong&gt; (HMAC over the method, path, body and a timestamp) typically allows a window of a few minutes. AWS Signature Version 4, for example, rejects requests whose time is too far from the server's, with an error like &lt;code&gt;RequestTimeTooSkewed&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pre-signed upload or download URLs&lt;/strong&gt; are usually created by the server, so they're fine, until the client decides on its own that a URL is "still valid for 10 minutes" using the device clock.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One-time codes&lt;/strong&gt; (TOTP) are computed from the current time. A device clock that's off by more than the allowed window produces codes that never work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the device builds any timestamp the server checks, use the server's time, not the device's.&lt;/p&gt;

&lt;h2&gt;
  
  
  Estimating server time
&lt;/h2&gt;

&lt;p&gt;The server already tells you its time: every HTTP response normally carries a &lt;code&gt;Date&lt;/code&gt; header.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On a response, parse &lt;code&gt;Date&lt;/code&gt; (it's an HTTP date, with one-second resolution) and compute &lt;code&gt;offset = serverDate - deviceNow&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Store the offset together with a monotonic timestamp (&lt;code&gt;SystemClock.elapsedRealtime()&lt;/code&gt; on Android, &lt;code&gt;ProcessInfo.processInfo.systemUptime&lt;/code&gt; on iOS), not the wall clock, which the user can change at any moment.&lt;/li&gt;
&lt;li&gt;When you need "now" for anything the server checks, use device time plus the offset.&lt;/li&gt;
&lt;li&gt;Ignore offsets of a second or two; they're latency and rounding. Log large ones, because "this user is 3 hours off" is very useful in a bug report.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Don't use this to "fix" the user's clock or to block the app. Just stop depending on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dates in the payload
&lt;/h2&gt;

&lt;p&gt;Separate from wrong clocks, date formatting on the device causes a steady stream of "works for me" bugs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Send timestamps in UTC with an explicit format&lt;/strong&gt;, such as ISO 8601 with &lt;code&gt;Z&lt;/code&gt; or an offset (&lt;code&gt;2026-11-25T09:30:00Z&lt;/code&gt;), or as epoch seconds. Not a local time without an offset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iOS &lt;code&gt;DateFormatter&lt;/code&gt; with a fixed format&lt;/strong&gt; needs &lt;code&gt;locale = Locale(identifier: "en_US_POSIX")&lt;/code&gt;. Without it, the user's 12/24-hour setting and calendar can change how the string is produced or parsed. Apple's technical Q&amp;amp;A on this exact problem has been around for years, and the bug still ships. &lt;code&gt;ISO8601DateFormatter&lt;/code&gt; avoids it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Android &lt;code&gt;SimpleDateFormat&lt;/code&gt;&lt;/strong&gt; uses the default locale, which can produce non-ASCII digits or a different calendar in some locales. Pass &lt;code&gt;Locale.US&lt;/code&gt; (or &lt;code&gt;Locale.ROOT&lt;/code&gt;) for machine-readable dates, or use &lt;code&gt;java.time&lt;/code&gt; with &lt;code&gt;DateTimeFormatter.ISO_INSTANT&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time zone changes&lt;/strong&gt; while the app is running (travel, or a manual change) can shift "today" boundaries. Compute "start of day" from the user's current time zone at the moment you need it, not one cached at launch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Set the device clock wrong.&lt;/strong&gt; Turn off automatic date and time, set it a day ahead, then a year behind. Open the app and walk through login, a normal request, an upload, and token refresh. Note which errors the user sees and whether any of them mention the date.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch the requests.&lt;/strong&gt; In a proxy or network inspector, look for timestamps the app builds itself (signature headers, query parameters, body fields) and compare them with the server's &lt;code&gt;Date&lt;/code&gt; header.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Change the locale and the 12/24-hour setting&lt;/strong&gt;, then repeat anything that formats or parses dates. A device set to a region with a non-Gregorian calendar or non-ASCII digits is a good stress test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simulators follow the host.&lt;/strong&gt; The iOS Simulator takes its time from the Mac, so clock tests are easier on a real device or an Android emulator, where the date can be set separately.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>mobile</category>
      <category>api</category>
    </item>
    <item>
      <title>The backend had a 2-minute blip and stayed down for 40. How mobile retries turn small outages into big ones.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Sun, 29 Nov 2026 02:45:35 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-backend-had-a-2-minute-blip-and-stayed-down-for-40-how-mobile-retries-turn-small-outages-into-4a60</link>
      <guid>https://dev.to/minpin_proxy/the-backend-had-a-2-minute-blip-and-stayed-down-for-40-how-mobile-retries-turn-small-outages-into-4a60</guid>
      <description>&lt;p&gt;The incident: the API slowed down for a couple of minutes, which happens. But it didn't recover when the cause was fixed. Traffic stayed at several times the normal level until someone rate limited the mobile clients at the edge. The extra traffic came from installed apps retrying.&lt;/p&gt;

&lt;p&gt;Retries are meant to hide short failures from users. Written carelessly, they multiply load exactly when the server can least handle it, and every installed copy of the app does it at once. Here's how that happens and what a well-behaved client does instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  How retries amplify load
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immediate retries.&lt;/strong&gt; A request fails, the app retries at once, maybe three times. During an outage every failing request becomes four requests. The server that was struggling with normal traffic now gets several times as much.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retries at several layers.&lt;/strong&gt; The networking library retries, the repository wrapper retries, and the screen has a "retry on error" effect. Three retries at each of three layers is up to 64 attempts for one user action.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Everyone retries at the same moment.&lt;/strong&gt; Fixed delays ("retry after 5 seconds") keep all clients in step. When the server comes back, it gets a spike from every client at once, falls over again, and the cycle repeats.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeouts that are retried.&lt;/strong&gt; A request that timed out may still be running on the server. Retrying it adds a second copy of the expensive work, not a replacement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App launch after an outage.&lt;/strong&gt; Users who saw errors reopen the app, and a cold start fires every startup request again. If those also retry, launch traffic can be the biggest spike of all.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to retry, and what not to
&lt;/h2&gt;

&lt;p&gt;Retry only when another attempt can plausibly succeed and is safe to repeat:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Usually retryable:&lt;/strong&gt; connection failures before the request was sent, &lt;code&gt;502&lt;/code&gt;, &lt;code&gt;503&lt;/code&gt;, &lt;code&gt;504&lt;/code&gt;, and &lt;code&gt;429&lt;/code&gt; (after waiting as told).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not retryable:&lt;/strong&gt; &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;401&lt;/code&gt;, &lt;code&gt;403&lt;/code&gt;, &lt;code&gt;404&lt;/code&gt;, &lt;code&gt;409&lt;/code&gt;, &lt;code&gt;422&lt;/code&gt;. Another identical request will get the same answer. For &lt;code&gt;401&lt;/code&gt;, refresh the token once and retry once; don't loop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Careful with non-idempotent requests.&lt;/strong&gt; A &lt;code&gt;POST&lt;/code&gt; that timed out may have succeeded. Retry it only with an idempotency key the server honors, or not at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also check what your library already does. OkHttp, for example, can silently retry some connection failures on its own (&lt;code&gt;retryOnConnectionFailure&lt;/code&gt;, on by default), so adding your own retry on top doubles it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back off, add jitter, cap it
&lt;/h2&gt;

&lt;p&gt;A reasonable default for a mobile client:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Exponential backoff:&lt;/strong&gt; wait roughly 1 s, 2 s, 4 s, 8 s between attempts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jitter:&lt;/strong&gt; randomize each delay (for example, a random value between zero and the backoff), so clients spread out instead of retrying in sync.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A small cap:&lt;/strong&gt; two or three attempts for a user-facing request, then show the error with a retry button. A person tapping "Retry" is a far better signal than an automatic loop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One layer only:&lt;/strong&gt; pick the place where retries happen (an interceptor, or the repository) and make every other layer pass errors through.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Listen to the server
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Retry-After&lt;/code&gt;:&lt;/strong&gt; on &lt;code&gt;429&lt;/code&gt; and &lt;code&gt;503&lt;/code&gt;, the server can say how long to wait, either as seconds or as an HTTP date. Honor it, and treat it as a minimum, not a suggestion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Back off globally, not per request.&lt;/strong&gt; If one request gets a &lt;code&gt;503&lt;/code&gt; with &lt;code&gt;Retry-After: 30&lt;/code&gt;, the others to the same host will almost certainly fail too. Pausing that host for 30 seconds across the app saves a lot of pointless traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circuit breaker:&lt;/strong&gt; after several consecutive failures to the same host, stop sending for a while and fail fast locally, then let a single request through to test whether it's back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A server-side switch:&lt;/strong&gt; a remote config value or a response header that tells clients to reduce polling or turn off non-essential calls is worth having before the next incident, not during it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Background work
&lt;/h2&gt;

&lt;p&gt;Background sync is where retry storms hide, because nobody is watching. Use the platform schedulers, which already add backoff and respect battery and network state: WorkManager with &lt;code&gt;setBackoffCriteria&lt;/code&gt; on Android, &lt;code&gt;BGTaskScheduler&lt;/code&gt; on iOS. Don't run your own tight retry loop inside a background task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fake an outage.&lt;/strong&gt; Point a debug build at a server or proxy rule that returns &lt;code&gt;503&lt;/code&gt; for every request for two minutes, then recovers. Count the requests the app sends during and right after the outage. A well-behaved client sends few requests during it and doesn't spike when it ends.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check &lt;code&gt;Retry-After&lt;/code&gt;.&lt;/strong&gt; Return &lt;code&gt;429&lt;/code&gt; with &lt;code&gt;Retry-After: 20&lt;/code&gt; and confirm nothing goes to that host for at least 20 seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Count the layers.&lt;/strong&gt; Make one request fail with a connection error and count the attempts that actually leave the device. If the number is larger than your configured retry count, another layer is retrying too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kill the app mid-outage and reopen it.&lt;/strong&gt; Watch the launch requests: they should respect the same backoff, not start from zero.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>api</category>
      <category>mobile</category>
    </item>
    <item>
      <title>The same item shows up twice in the feed, and another one never shows up. Pagination bugs in infinite scroll.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Sat, 28 Nov 2026 02:44:53 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-same-item-shows-up-twice-in-the-feed-and-another-one-never-shows-up-pagination-bugs-in-5h00</link>
      <guid>https://dev.to/minpin_proxy/the-same-item-shows-up-twice-in-the-feed-and-another-one-never-shows-up-pagination-bugs-in-5h00</guid>
      <description>&lt;p&gt;The bug reports: "I saw the same post twice while scrolling." "A message I know exists never appeared in the list." Both are hard to reproduce, because they only happen when the data changes while someone is scrolling. In production that's all the time.&lt;/p&gt;

&lt;p&gt;Usually the cause is the pagination scheme, not the list view. Here's how it goes wrong and what to use instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Offset pagination shifts under you
&lt;/h2&gt;

&lt;p&gt;The classic API: &lt;code&gt;GET /items?offset=40&amp;amp;limit=20&lt;/code&gt;, sorted newest first.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A new item is added at the top&lt;/strong&gt; between page 2 and page 3. Everything moves down by one. The item that was at position 39 is now at 40, so page 3 starts with an item the user has already seen. Duplicate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An item is deleted&lt;/strong&gt; above the current position. Everything moves up by one. The item that was at 40 is now at 39, it falls between page 2 and page 3, and the user never sees it. Missing item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The client did nothing wrong. Offsets describe positions, and positions change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sorting that isn't unique
&lt;/h2&gt;

&lt;p&gt;Even without inserts, a sort like &lt;code&gt;ORDER BY created_at DESC&lt;/code&gt; is not stable when two rows share the same timestamp. The database can return tied rows in a different order on each query, so a row can land on both page 2 and page 3, or on neither. This happens a lot with bulk imports and with timestamps rounded to the second.&lt;/p&gt;

&lt;p&gt;Always add a unique tie-breaker: &lt;code&gt;ORDER BY created_at DESC, id DESC&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cursor (keyset) pagination
&lt;/h2&gt;

&lt;p&gt;Instead of "skip 40 rows", the client says "give me items after this one":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="na"&gt;GET /items?limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;
→ &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"next_cursor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"eyJjIjoiMjAyNi0xMS0yM1QwOTowMDowMFoiLCJpZCI6ODQyfQ"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="na"&gt;GET /items?limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;cursor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;eyJj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cursor encodes the sort key of the last item (here &lt;code&gt;created_at&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt;), and the server queries &lt;code&gt;WHERE (created_at, id) &amp;lt; (:c, :id) ORDER BY created_at DESC, id DESC LIMIT 20&lt;/code&gt;. New items at the top don't move anything after the cursor, and deleted items simply aren't returned.&lt;/p&gt;

&lt;p&gt;Practical points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Make the cursor opaque&lt;/strong&gt; (for example base64-encoded JSON) so clients don't build it themselves and the server can change it later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return &lt;code&gt;next_cursor: null&lt;/code&gt; on the last page.&lt;/strong&gt; Don't make the client guess from &lt;code&gt;items.count &amp;lt; limit&lt;/code&gt;, which is wrong when the server filters rows after the query.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Index the sort columns&lt;/strong&gt; together, or keyset queries get slow on big tables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't promise "jump to page 37".&lt;/strong&gt; Keyset pagination goes forward (and backward with a second cursor), not to arbitrary pages. For feeds that's fine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The client still needs to protect itself
&lt;/h2&gt;

&lt;p&gt;Even with cursors, a few client habits prevent most of the remaining reports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;De-duplicate by ID&lt;/strong&gt; when appending a page. Keep a set of IDs already in the list, or let the list's diffing (&lt;code&gt;DiffableDataSource&lt;/code&gt;, &lt;code&gt;DiffUtil&lt;/code&gt;, Paging 3) work with stable IDs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't load the same page twice.&lt;/strong&gt; Scroll-triggered loading often fires again before the first request returns. Track one in-flight request per cursor and ignore triggers while it runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignore stale responses.&lt;/strong&gt; If the user pulls to refresh while page 4 is loading, the old page 4 response can arrive after the refresh and append to the new list. Tag each request with the list "generation" and drop responses from an older one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New items at the top are a separate request.&lt;/strong&gt; Fetch "items newer than the first one I have" on refresh, instead of reloading from offset 0 and merging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On Android, Paging 3 handles in-flight tracking and page keys for you (&lt;code&gt;PagingSource&lt;/code&gt; with the cursor as the key). On iOS there's no built-in equivalent, so the in-flight and generation checks are yours to write.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;p&gt;These bugs don't show up with a static test database. To reproduce them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Load the first page in the app.&lt;/li&gt;
&lt;li&gt;Insert a few items at the top on the server (or delete a few from the first page).&lt;/li&gt;
&lt;li&gt;Scroll to load the next page.&lt;/li&gt;
&lt;li&gt;With offset pagination you'll see duplicates (after inserts) or gaps (after deletes). With cursors you shouldn't see either.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Also watch the requests while scrolling fast: you should see each cursor requested once. Two identical page requests a few milliseconds apart mean the in-flight check is missing.&lt;/p&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>api</category>
      <category>mobile</category>
    </item>
    <item>
      <title>The chat says "connected" and no messages arrive. Keeping WebSockets alive on mobile networks.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Wed, 25 Nov 2026 02:06:10 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-chat-says-connected-and-no-messages-arrive-keeping-websockets-alive-on-mobile-networks-215h</link>
      <guid>https://dev.to/minpin_proxy/the-chat-says-connected-and-no-messages-arrive-keeping-websockets-alive-on-mobile-networks-215h</guid>
      <description>&lt;p&gt;The bug: the app shows a green "connected" dot, but new messages stop arriving. The user pulls to refresh, the missed messages appear, and live updates work again for a while. The server logs show the connection closed minutes ago, or never show it closing at all.&lt;/p&gt;

&lt;p&gt;A WebSocket is one long-lived TCP connection. Phones are bad at keeping those, and they often don't tell the app when one dies. Here's why, and what a reliable client does about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the connection dies without anyone noticing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NAT and carrier timeouts.&lt;/strong&gt; Mobile networks put devices behind NAT gateways that drop idle TCP mappings, sometimes after only a few minutes without traffic. Neither end gets a close frame or a reset. The next message from the server just disappears.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network switches.&lt;/strong&gt; When the phone moves from Wi-Fi to cellular, its IP address changes. The old TCP connection can't move with it. Until a write fails or a timeout fires, the client may still think it's connected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The app goes to the background.&lt;/strong&gt; iOS suspends apps shortly after they leave the screen, and Android restricts background network access more with each release. A socket that belongs to a suspended app stops being read, and the server or a proxy closes it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Proxies and load balancers in between.&lt;/strong&gt; Many have an idle timeout for WebSocket connections (often 60 seconds by default on some load balancers) and close connections that carry no frames for that long.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The common pattern: TCP only notices a dead peer when it tries to send. A client that only listens can sit on a dead connection for a very long time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Heartbeats: detect the dead connection yourself
&lt;/h2&gt;

&lt;p&gt;Send something regularly and expect something back.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OkHttp&lt;/strong&gt;: &lt;code&gt;OkHttpClient.Builder().pingInterval(20, TimeUnit.SECONDS)&lt;/code&gt; sends WebSocket ping frames. If a pong doesn't arrive in time, OkHttp fails the socket and calls &lt;code&gt;onFailure&lt;/code&gt;, which is where you reconnect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt;: &lt;code&gt;URLSessionWebSocketTask.sendPing(pongReceiveHandler:)&lt;/code&gt; sends a ping and calls the handler when the pong arrives or with an error. It doesn't schedule itself, so run it on a timer and treat a missing pong as a dead connection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application-level heartbeat&lt;/strong&gt;: if a proxy in the path handles ping frames itself, or you need the server to confirm the session is still valid, send a small app message (&lt;code&gt;{"type":"ping"}&lt;/code&gt;) and expect a reply.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pick an interval shorter than the shortest idle timeout in the path (often 20 to 30 seconds is used), and weigh it against battery use. Pings also keep NAT mappings alive while the app is in the foreground.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconnect properly
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Back off with jitter.&lt;/strong&gt; Retry after 1, 2, 4, 8 seconds and so on, up to a cap, with a random component. If the server restarts and every client reconnects at the same instant, the reconnect storm can take it down again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reconnect on network change.&lt;/strong&gt; Watch for path changes (&lt;code&gt;NWPathMonitor&lt;/code&gt; on iOS, &lt;code&gt;ConnectivityManager.NetworkCallback&lt;/code&gt; on Android) and reconnect right away instead of waiting for a heartbeat to fail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Close on background, reconnect on foreground.&lt;/strong&gt; Don't fight the OS. When the app goes to the background, close the socket cleanly and rely on push notifications for anything urgent. When it comes back, reconnect and catch up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show the real state.&lt;/strong&gt; "Connecting…" after a failed heartbeat is better than a green dot on a dead socket.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Don't lose messages across reconnects
&lt;/h2&gt;

&lt;p&gt;Reconnecting gives you a new connection, not the messages sent while the old one was dead. The server has to help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give every message (or event) an increasing ID or sequence number.&lt;/li&gt;
&lt;li&gt;On reconnect, the client sends the last ID it processed, and the server sends everything after it, or the client fetches the gap over a normal HTTP endpoint.&lt;/li&gt;
&lt;li&gt;Make message handling idempotent on the client, because a message near the reconnect can arrive twice.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without this, every reconnect is a chance to miss a message silently, which is exactly the bug users report.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Idle timeout&lt;/strong&gt;: connect, then send nothing for longer than your proxy's or load balancer's idle timeout. With heartbeats on, the connection should survive. With them off, you should see it die, which proves the timeout exists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network switch&lt;/strong&gt;: connect on Wi-Fi, turn Wi-Fi off so the phone moves to cellular, and send a message from another client. The app should reconnect and show it, within roughly one heartbeat interval.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Background&lt;/strong&gt;: send the app to the background for a few minutes, send messages from another client, then reopen the app. It should reconnect and show every missed message, in order, without duplicates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server restart&lt;/strong&gt;: restart the WebSocket server with several clients connected and watch the reconnect timing. With jitter, the reconnects spread out instead of arriving at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bad network&lt;/strong&gt;: run the same tests on a slow, lossy network profile. Watch the frames in a WebSocket-capable inspector or proxy to confirm the pings and pongs actually go over the wire.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>websockets</category>
      <category>mobile</category>
    </item>
    <item>
      <title>It works in curl and returns 400 from the app. Finding the difference between two "identical" requests.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Tue, 24 Nov 2026 07:39:47 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/it-works-in-curl-and-returns-400-from-the-app-finding-the-difference-between-two-identical-387e</link>
      <guid>https://dev.to/minpin_proxy/it-works-in-curl-and-returns-400-from-the-app-finding-the-difference-between-two-identical-387e</guid>
      <description>&lt;p&gt;The bug: the backend developer runs the request with curl and gets a 200. The app sends "the same request" and gets a 400, or a 415, or a 403 from something in front of the server. Everyone agrees the requests are identical. They aren't. The networking library added, changed or dropped something on the way out.&lt;/p&gt;

&lt;p&gt;Here's where the differences usually are, and how to find them without guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step one: compare the real requests
&lt;/h2&gt;

&lt;p&gt;Don't compare the app's code with the curl command. Compare what was actually sent:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Capture the app's request on the wire (a debugging proxy, or the platform's network inspector), including all headers and the exact body bytes.&lt;/li&gt;
&lt;li&gt;Export it as a curl command and run that. If it fails the same way, the problem is in the request, not the app.&lt;/li&gt;
&lt;li&gt;Remove or change one header (or one body field) at a time until it succeeds. The last thing you changed is the cause.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This takes ten minutes and replaces most of the arguing. The usual suspects below tell you where to look first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Content-Type
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt;: if you set &lt;code&gt;httpBody&lt;/code&gt; on a &lt;code&gt;URLRequest&lt;/code&gt; and don't set &lt;code&gt;Content-Type&lt;/code&gt;, the request goes out as &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt;. A JSON body with that header gets a 400 or 415 from servers that check, or gets parsed as an empty form by frameworks that don't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OkHttp&lt;/strong&gt;: &lt;code&gt;"...".toRequestBody("application/json".toMediaType())&lt;/code&gt; sends &lt;code&gt;application/json; charset=utf-8&lt;/code&gt;, because OkHttp adds the charset when the media type has none. Most servers accept it. A few strict ones or hand-written checks compare the whole header string and don't.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The JSON body isn't what you think
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Swift dates&lt;/strong&gt;: &lt;code&gt;JSONEncoder&lt;/code&gt;'s default &lt;code&gt;dateEncodingStrategy&lt;/code&gt; is &lt;code&gt;.deferredToDate&lt;/code&gt;, which writes a &lt;code&gt;Date&lt;/code&gt; as a number of seconds since January 1, 2001, not since 1970 and not as ISO 8601. A server that reads it as Unix time gets a date about 31 years too early, and a stricter one rejects the field. Set &lt;code&gt;.iso8601&lt;/code&gt; (or whatever the API expects) on the encoder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Missing fields&lt;/strong&gt;: Gson and Moshi leave out &lt;code&gt;null&lt;/code&gt; properties by default, and kotlinx.serialization leaves out properties that still have their default value unless &lt;code&gt;encodeDefaults = true&lt;/code&gt;. An API that requires the field to be present, even as &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;0&lt;/code&gt;, returns a validation error for a field the app "definitely sends".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key names&lt;/strong&gt;: a &lt;code&gt;keyEncodingStrategy&lt;/code&gt; of &lt;code&gt;.convertToSnakeCase&lt;/code&gt;, or a &lt;code&gt;@SerializedName&lt;/code&gt; / &lt;code&gt;@Json(name=)&lt;/code&gt; missing on one property, sends &lt;code&gt;userId&lt;/code&gt; where the server expects &lt;code&gt;user_id&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The query string
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;URLComponents&lt;/code&gt; with &lt;code&gt;URLQueryItem&lt;/code&gt; doesn't percent-encode &lt;code&gt;+&lt;/code&gt;. Many servers decode &lt;code&gt;+&lt;/code&gt; in a query string as a space, so &lt;code&gt;email=a+b@example.com&lt;/code&gt; arrives as &lt;code&gt;a b@example.com&lt;/code&gt;. Encode &lt;code&gt;+&lt;/code&gt; as &lt;code&gt;%2B&lt;/code&gt; yourself for those values. On Android, check how your builder encodes spaces versus &lt;code&gt;+&lt;/code&gt; for the same reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  Headers the library adds or removes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User-Agent&lt;/strong&gt;: the app sends something like &lt;code&gt;MyApp/1.0 CFNetwork/... Darwin/...&lt;/code&gt; or &lt;code&gt;okhttp/4.x&lt;/code&gt;. Some WAF and bot-protection rules block or challenge default library user agents, and the 403 comes from the edge, not your server. The response body (often HTML in a JSON API) is the hint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorization after a redirect&lt;/strong&gt;: OkHttp drops the &lt;code&gt;Authorization&lt;/code&gt; header when following a redirect to a different host. Other clients have their own rules. If the API redirects (&lt;code&gt;http&lt;/code&gt; to &lt;code&gt;https&lt;/code&gt;, a missing trailing slash, an old domain), the second request may go out without credentials and fail with a 401 that the first request never got.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redirects and methods&lt;/strong&gt;: a &lt;code&gt;301&lt;/code&gt; or &lt;code&gt;302&lt;/code&gt; in reply to a &lt;code&gt;POST&lt;/code&gt; is usually followed with a &lt;code&gt;GET&lt;/code&gt; and no body. The server then sees a body-less &lt;code&gt;GET&lt;/code&gt; on an endpoint that only takes &lt;code&gt;POST&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cookies&lt;/strong&gt;: curl sends none unless told to. The app's cookie store may send an old session cookie that the server prefers over the &lt;code&gt;Authorization&lt;/code&gt; header.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How the body is sent
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chunked uploads&lt;/strong&gt;: if the body length isn't known up front (an input stream on iOS, a &lt;code&gt;RequestBody&lt;/code&gt; with &lt;code&gt;contentLength()&lt;/code&gt; of &lt;code&gt;-1&lt;/code&gt; on OkHttp), the request uses &lt;code&gt;Transfer-Encoding: chunked&lt;/code&gt; instead of &lt;code&gt;Content-Length&lt;/code&gt;. Some proxies, gateways and older servers reject chunked request bodies or treat them as empty.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GET with a body&lt;/strong&gt;: OkHttp refuses to build it, and &lt;code&gt;URLSession&lt;/code&gt; fails the request on recent iOS versions. If the API was designed around a &lt;code&gt;GET&lt;/code&gt; with a JSON body because curl allows it, the mobile client can't send it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Making it not happen again
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Write a test that encodes each request model and compares the JSON to a fixture the backend agrees with, including dates, nulls and key names.&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;Content-Type&lt;/code&gt;, &lt;code&gt;Accept&lt;/code&gt; and the date strategy in one place (one encoder, one interceptor), not per call.&lt;/li&gt;
&lt;li&gt;Log the method, URL, status and a request ID for failed requests in debug builds, so the next "works in curl" report starts with the real request.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>api</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Every request failed the morning the certificate renewed. Certificate pinning on mobile, and how to stop it bricking your app.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Mon, 23 Nov 2026 02:44:57 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/every-request-failed-the-morning-the-certificate-renewed-certificate-pinning-on-mobile-and-how-to-5gk2</link>
      <guid>https://dev.to/minpin_proxy/every-request-failed-the-morning-the-certificate-renewed-certificate-pinning-on-mobile-and-how-to-5gk2</guid>
      <description>&lt;p&gt;The incident: nothing was deployed, but overnight every request from the mobile app started failing. The website works. The API works from curl. Only the app is broken, for every user, and the backend team sees no errors because the requests never arrive.&lt;/p&gt;

&lt;p&gt;Then someone remembers the app pins the server's certificate, and the certificate renewed last night.&lt;/p&gt;

&lt;p&gt;Pinning means the app accepts only specific keys for your server, on top of normal certificate validation. It protects against a mis-issued or locally installed certificate. It also means any change to those keys on the server breaks every installed copy of the app until users update. Here's how to pin without that risk, or decide not to pin.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's actually pinned
&lt;/h2&gt;

&lt;p&gt;There are three common choices, and they fail differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The leaf certificate&lt;/strong&gt; (the whole cert): breaks at every renewal. Avoid.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The leaf's public key (SPKI hash)&lt;/strong&gt;: survives renewal only if the new certificate reuses the same key. Many ACME clients generate a new key at each renewal by default, so this breaks silently on the renewal date.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An intermediate or root CA's public key&lt;/strong&gt;: survives renewals, but breaks if your CA changes its intermediates or you switch CAs. Let's Encrypt, for example, issues from several intermediates and can rotate them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Certificate lifetimes are also getting shorter: the CA/Browser Forum has set maximum public TLS certificate lifetimes to drop in stages to 47 days by 2029. More renewals mean more chances for a pin to break.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pin safely, if you pin
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Pin public keys (SPKI SHA-256), never whole certificates.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Always include a backup pin&lt;/strong&gt;: the hash of a key that isn't in use yet, kept offline, so you can switch to it without an app update. Two or more pins is the rule on both platforms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pin at the right level.&lt;/strong&gt; Pinning your CA's keys (several of them, including the root) is the safer choice for most teams. Pinning your own leaf key is stricter, but then the key must be reused on renewal, and that has to be written down in the renewal process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set an expiration where the platform supports it&lt;/strong&gt;, so an old app version stops enforcing pins instead of failing forever.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tell whoever runs the certificates.&lt;/strong&gt; Most pinning outages come from a routine change made by someone who didn't know the app depends on the key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Getting a SPKI hash from a live server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openssl s_client -connect api.example.com:443 -servername api.example.com &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;/dev/null \
  &lt;span class="o"&gt;|&lt;/span&gt; openssl x509 -pubkey -noout \
  &lt;span class="o"&gt;|&lt;/span&gt; openssl pkey -pubin -outform der \
  &lt;span class="o"&gt;|&lt;/span&gt; openssl dgst -sha256 -binary \
  &lt;span class="o"&gt;|&lt;/span&gt; openssl enc -base64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  iOS
&lt;/h2&gt;

&lt;p&gt;Since iOS 14 you can pin in &lt;code&gt;Info.plist&lt;/code&gt; without code: under &lt;code&gt;NSAppTransportSecurity&lt;/code&gt; &amp;gt; &lt;code&gt;NSPinnedDomains&lt;/code&gt;, add your domain with &lt;code&gt;NSPinnedCAIdentities&lt;/code&gt; or &lt;code&gt;NSPinnedLeafIdentities&lt;/code&gt;, each an array of &lt;code&gt;SPKI-SHA256-BASE64&lt;/code&gt; values. There's no expiration setting, so backup pins matter even more here.&lt;/p&gt;

&lt;p&gt;If you pin in code instead (a &lt;code&gt;URLSessionDelegate&lt;/code&gt; that checks the server trust), be careful about what you hash, and make sure the failure path is logged. A delegate that cancels the challenge produces a generic cancelled error, which tells nobody that pinning was the cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  Android
&lt;/h2&gt;

&lt;p&gt;Use the network security config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;network-security-config&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;domain-config&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;domain&lt;/span&gt; &lt;span class="na"&gt;includeSubdomains&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;api.example.com&lt;span class="nt"&gt;&amp;lt;/domain&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;pin-set&lt;/span&gt; &lt;span class="na"&gt;expiration&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"2027-06-01"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;pin&lt;/span&gt; &lt;span class="na"&gt;digest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"SHA-256"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;primaryKeyHashBase64=&lt;span class="nt"&gt;&amp;lt;/pin&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;pin&lt;/span&gt; &lt;span class="na"&gt;digest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"SHA-256"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;backupKeyHashBase64=&lt;span class="nt"&gt;&amp;lt;/pin&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/pin-set&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/domain-config&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/network-security-config&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the &lt;code&gt;expiration&lt;/code&gt; date, pinning is no longer enforced for that domain, which limits the damage from an old app version nobody updated.&lt;/p&gt;

&lt;p&gt;With OkHttp, &lt;code&gt;CertificatePinner&lt;/code&gt; does the same in code and throws &lt;code&gt;SSLPeerUnverifiedException&lt;/code&gt; with "Certificate pinning failure!" and the list of hashes the server actually presented, which is useful when debugging.&lt;/p&gt;

&lt;p&gt;Android's documentation itself recommends against pinning for most apps, because of the risk of exactly this outage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Debug builds
&lt;/h2&gt;

&lt;p&gt;Pinning blocks HTTPS inspection with a debugging proxy, because the proxy presents its own certificate. Keep pinning in release builds and turn it off in debug builds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Android&lt;/strong&gt;: in &lt;code&gt;&amp;lt;debug-overrides&amp;gt;&lt;/code&gt;, trust user CAs with &lt;code&gt;&amp;lt;certificates src="user" overridePins="true" /&amp;gt;&lt;/code&gt;. It applies only to debuggable builds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt;: keep the pinning config in a release-only &lt;code&gt;Info.plist&lt;/code&gt; or behind a build setting, so debug builds use normal validation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing before it happens in production
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Put the next key's hash in the app before you need it, then do a planned rotation on a staging server: switch staging to the backup key and confirm the current app still connects.&lt;/li&gt;
&lt;li&gt;Point a test build at a server with a valid certificate from a different CA. It must fail, and the failure should show up in your logs as a pinning failure, not a generic network error.&lt;/li&gt;
&lt;li&gt;Add the pin hashes and their expiry to the same runbook as the certificate renewal, so the next person to renew knows the app depends on them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Or don't pin
&lt;/h2&gt;

&lt;p&gt;For many apps, standard TLS validation is enough, together with Certificate Transparency checks where the platform enforces them. Pinning is worth it when the threat model really needs it, and only with backup pins, expiry, and a rotation plan. Without those it causes more outages than attacks it stops.&lt;/p&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>security</category>
      <category>mobile</category>
    </item>
    <item>
      <title>The app shows yesterday's data and nobody wrote any cache code. HTTP caching on mobile, from the response headers up.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Sun, 22 Nov 2026 02:44:49 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-app-shows-yesterdays-data-and-nobody-wrote-any-cache-code-http-caching-on-mobile-from-the-4fgo</link>
      <guid>https://dev.to/minpin_proxy/the-app-shows-yesterdays-data-and-nobody-wrote-any-cache-code-http-caching-on-mobile-from-the-4fgo</guid>
      <description>&lt;p&gt;The bug: a user changes something on the web, opens the app, and sees the old value. Pull to refresh doesn't help. Ten minutes later, or after reinstalling, it's fine. Nobody on the team wrote a cache, so everyone looks for a bug in the backend first.&lt;/p&gt;

&lt;p&gt;Often there is a cache, and it's the HTTP cache built into the networking library. It follows the response headers your server sends, including the headers it doesn't send.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who caches by default
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;iOS, &lt;code&gt;URLSession&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;URLSession.shared&lt;/code&gt; and the default configuration use &lt;code&gt;URLCache.shared&lt;/code&gt;, with the cache policy &lt;code&gt;.useProtocolCachePolicy&lt;/code&gt;. So every app has an HTTP cache, in memory and on disk, unless someone turns it off.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Android, OkHttp&lt;/strong&gt;: no cache until you add one with &lt;code&gt;Cache(directory, maxSize)&lt;/code&gt; on the &lt;code&gt;OkHttpClient.Builder&lt;/code&gt;. Many apps do, often copied from a setup guide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Android, &lt;code&gt;HttpURLConnection&lt;/code&gt;&lt;/strong&gt;: no cache unless &lt;code&gt;HttpResponseCache.install()&lt;/code&gt; was called.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So "we never wrote cache code" is true, and on iOS it's also irrelevant.&lt;/p&gt;

&lt;h2&gt;
  
  
  The header that isn't there
&lt;/h2&gt;

&lt;p&gt;If a response has &lt;code&gt;Cache-Control: max-age=...&lt;/code&gt; or &lt;code&gt;Expires&lt;/code&gt;, the cache does what it says. The surprise comes when a response has &lt;strong&gt;no&lt;/strong&gt; caching headers but does have &lt;code&gt;Last-Modified&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The HTTP caching spec (RFC 9111) lets a cache pick a freshness lifetime on its own in that case, called heuristic freshness. The common rule is 10% of the time since &lt;code&gt;Last-Modified&lt;/code&gt;. A JSON response whose &lt;code&gt;Last-Modified&lt;/code&gt; says it changed 10 days ago can be reused for about a day, without any request going to the server.&lt;/p&gt;

&lt;p&gt;iOS's URL loading system applies this. OkHttp applies it too, for URLs without a query string. Frameworks and CDNs add &lt;code&gt;Last-Modified&lt;/code&gt; to responses all the time, often for static files that later became API-like endpoints, so this shows up without anyone choosing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The directives, briefly
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;no-store&lt;/code&gt;: don't write it anywhere. Use this for tokens and personal data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;no-cache&lt;/code&gt;: store it, but check with the server before every reuse. It does &lt;strong&gt;not&lt;/strong&gt; mean "don't cache".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;max-age=60&lt;/code&gt;: fresh for 60 seconds, then check again.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;private&lt;/code&gt;: only the client may cache it, not shared caches like CDNs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ETag&lt;/code&gt; + &lt;code&gt;If-None-Match&lt;/code&gt;: when the client checks again, the server can answer &lt;code&gt;304 Not Modified&lt;/code&gt; with no body, and the client uses its stored copy. That's cheap, and it's what you want for most API reads.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Vary&lt;/code&gt;: the stored copy only matches requests with the same values for the listed headers. If responses depend on &lt;code&gt;Authorization&lt;/code&gt; or &lt;code&gt;Accept-Language&lt;/code&gt;, say so here, or one user's cached response can be served for another account on the same device.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Finding out whether a response came from the cache
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;iOS&lt;/strong&gt;: collect &lt;code&gt;URLSessionTaskMetrics&lt;/code&gt; in &lt;code&gt;urlSession(_:task:didFinishCollecting:)&lt;/code&gt;. For each transaction, &lt;code&gt;resourceFetchType&lt;/code&gt; is &lt;code&gt;.localCache&lt;/code&gt; when nothing went over the network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OkHttp&lt;/strong&gt;: on the &lt;code&gt;Response&lt;/code&gt;, &lt;code&gt;cacheResponse&lt;/code&gt; is non-null when the cache was involved and &lt;code&gt;networkResponse&lt;/code&gt; is non-null when the network was. Both non-null means a conditional request (usually a &lt;code&gt;304&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In a debugging proxy&lt;/strong&gt;: a response served from the cache never reaches the proxy. If the screen loads and the request isn't in the capture, that's the answer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fixing it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fix the server first.&lt;/strong&gt; Every API response should say what it wants: &lt;code&gt;Cache-Control: no-store&lt;/code&gt; for sensitive data, &lt;code&gt;no-cache&lt;/code&gt; plus an &lt;code&gt;ETag&lt;/code&gt; for data that must always be current, or a short &lt;code&gt;max-age&lt;/code&gt; where a little staleness is fine. Explicit headers end the heuristic guessing on every client at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make pull to refresh mean it.&lt;/strong&gt; On iOS, set &lt;code&gt;request.cachePolicy = .reloadIgnoringLocalCacheData&lt;/code&gt; for that request. On OkHttp, add &lt;code&gt;CacheControl.FORCE_NETWORK&lt;/code&gt; to that request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't turn the cache off globally.&lt;/strong&gt; Setting &lt;code&gt;urlCache = nil&lt;/code&gt; or removing the OkHttp cache fixes the symptom and makes every image and config fetch slower. Fix the headers instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clear it on logout.&lt;/strong&gt; &lt;code&gt;URLCache.shared.removeAllCachedResponses()&lt;/code&gt; on iOS, &lt;code&gt;cache.evictAll()&lt;/code&gt; on OkHttp, so the next account doesn't see the previous one's responses.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;p&gt;Change a value on the server, then open the app's screen without reinstalling. Check the response headers of that request in a capture: if there's no &lt;code&gt;Cache-Control&lt;/code&gt; and there is a &lt;code&gt;Last-Modified&lt;/code&gt;, you've found the cause before reading any app code.&lt;/p&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>mobile</category>
      <category>http</category>
    </item>
    <item>
      <title>The upload works in the office and dies at 80% on the train. Making large uploads survive mobile networks.</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Sat, 21 Nov 2026 06:41:06 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/the-upload-works-in-the-office-and-dies-at-80-on-the-train-making-large-uploads-survive-mobile-2215</link>
      <guid>https://dev.to/minpin_proxy/the-upload-works-in-the-office-and-dies-at-80-on-the-train-making-large-uploads-survive-mobile-2215</guid>
      <description>&lt;p&gt;The bug: users attach a video or a batch of photos, the progress bar gets most of the way, and then the upload fails and starts again from zero. On office Wi-Fi it never happens. On a phone it happens a lot, because a long upload on a mobile network is very likely to hit at least one of these: a network switch (Wi-Fi to cellular), a dead zone, the user leaving the app, or a timeout somewhere between the phone and your server.&lt;/p&gt;

&lt;p&gt;A single &lt;code&gt;POST&lt;/code&gt; with the whole file in the body has no way to recover from any of them. Here's what does.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Find out where it actually fails
&lt;/h2&gt;

&lt;p&gt;Before changing the client, check the path the upload takes. A few limits are hit only by large or slow uploads, and they look like network failures from the phone:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;nginx &lt;code&gt;client_max_body_size&lt;/code&gt;&lt;/strong&gt; defaults to 1 MB. Larger bodies get &lt;code&gt;413 Request Entity Too Large&lt;/code&gt;, sometimes before the client has finished sending, which some clients report as a broken connection instead of a 413.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;nginx &lt;code&gt;client_body_timeout&lt;/code&gt;&lt;/strong&gt; (default 60 seconds) closes the connection if the client sends nothing for that long. A phone in a tunnel easily does that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CDNs and load balancers&lt;/strong&gt; have their own body size and idle limits. Some plans cap request bodies at 100 MB no matter what your server allows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your app server's own limit&lt;/strong&gt; (body parser size, multipart limit, request timeout).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Test by uploading a file just over each limit from a fast connection. If that fails, the problem isn't the mobile network.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Get the timeouts right on the client
&lt;/h2&gt;

&lt;p&gt;On iOS, &lt;code&gt;URLSessionConfiguration.timeoutIntervalForRequest&lt;/code&gt; (default 60 s) is an idle timeout: it fires when no data moves for that long, not when the whole request takes longer than 60 s. &lt;code&gt;timeoutIntervalForResource&lt;/code&gt; (default 7 days) is the total limit. Setting the request timeout to a few minutes "because uploads are slow" mostly delays the error. Leave it, and make the upload resumable instead.&lt;/p&gt;

&lt;p&gt;On Android with OkHttp, &lt;code&gt;writeTimeout&lt;/code&gt; is also per write, not for the whole body. &lt;code&gt;callTimeout&lt;/code&gt; is the total, and it's off by default. If someone set &lt;code&gt;callTimeout&lt;/code&gt; to 30 seconds for the whole app, every upload that takes longer than 30 seconds fails, and that only happens on slow networks.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Make the upload resumable
&lt;/h2&gt;

&lt;p&gt;The fix that actually solves it: upload in pieces, and let the client ask the server how much it already has.&lt;/p&gt;

&lt;p&gt;You don't need to design this yourself. Common options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tus&lt;/strong&gt;, an open protocol for resumable uploads with server and client libraries for most stacks. The client creates an upload, sends the file with &lt;code&gt;PATCH&lt;/code&gt; requests carrying an &lt;code&gt;Upload-Offset&lt;/code&gt; header, and after a failure sends &lt;code&gt;HEAD&lt;/code&gt; to learn the offset the server has and continues from there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;S3 multipart upload&lt;/strong&gt;: split the file into parts (at least 5 MiB each, except the last; at most 10,000 parts), upload each part with its own presigned URL, then complete the upload. A failed part is retried on its own. Remember to abort or expire unfinished uploads, because their parts are stored and billed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Cloud Storage resumable uploads&lt;/strong&gt;: start a session, upload chunks, and query the session for the committed size after an interruption.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever you use, the client has to store the upload ID and the part list on disk, not in memory, so it can continue after the app is killed.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Keep uploading when the user leaves the app
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;iOS&lt;/strong&gt;: use a background &lt;code&gt;URLSession&lt;/code&gt; (&lt;code&gt;URLSessionConfiguration.background(withIdentifier:)&lt;/code&gt;) with &lt;code&gt;uploadTask(with:fromFile:)&lt;/code&gt;. Background sessions only upload from files, so write the data (or each part) to a file first. The system carries on with the upload while your app is suspended or terminated by the system, and relaunches the app in the background when it's done. (If the user force-quits the app, iOS cancels its background transfers, which is another reason to keep the upload state on disk and resume on the next launch.) Implement &lt;code&gt;application(_:handleEventsForBackgroundURLSession:completionHandler:)&lt;/code&gt; and call the completion handler after processing the events. Each part of a multipart upload can be its own background upload task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android&lt;/strong&gt;: use WorkManager with a &lt;code&gt;NetworkType.CONNECTED&lt;/code&gt; constraint so the work waits for a network and retries with backoff. For long uploads the user started, run it as a foreground worker with a progress notification (&lt;code&gt;setForeground&lt;/code&gt;); on Android 14 and later that foreground service needs the &lt;code&gt;dataSync&lt;/code&gt; type declared. Android 14 also added user-initiated data transfer jobs in JobScheduler, made for exactly this case.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Send less
&lt;/h2&gt;

&lt;p&gt;The cheapest fix: a 12-megapixel photo doesn't need to go up at full size if the server shrinks it anyway. Resize and recompress on the device first. For video, check whether the server transcodes it anyway, and if it does, upload a lower bitrate version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use a slow network profile (on a Mac, Network Link Conditioner's "3G" or "Very Bad Network") and start a large upload.&lt;/li&gt;
&lt;li&gt;Halfway through, turn on airplane mode for 30 seconds, then turn it off. The upload should continue from where it was, not from 0%.&lt;/li&gt;
&lt;li&gt;Start an upload, send the app to the background, and wait: it should finish without the app in front. Then force-quit it during an upload and open it again: it should pick up from the stored offset.&lt;/li&gt;
&lt;li&gt;Watch the requests: after an interruption you should see the "how much do you have?" request (&lt;code&gt;HEAD&lt;/code&gt; for tus, list parts for S3) followed by only the missing bytes.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>mobile</category>
      <category>ios</category>
      <category>android</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Works on Wi-Fi, fails on some cellular networks: hardcoded IPv4 and the IPv6-only carriers</title>
      <dc:creator>MinPin Proxy</dc:creator>
      <pubDate>Thu, 19 Nov 2026 02:36:37 +0000</pubDate>
      <link>https://dev.to/minpin_proxy/works-on-wi-fi-fails-on-some-cellular-networks-hardcoded-ipv4-and-the-ipv6-only-carriers-55k9</link>
      <guid>https://dev.to/minpin_proxy/works-on-wi-fi-fails-on-some-cellular-networks-hardcoded-ipv4-and-the-ipv6-only-carriers-55k9</guid>
      <description>&lt;p&gt;The report: "the app can't connect on my phone network, but it's fine on Wi-Fi". Support asks for the carrier, and the answer is one of the large mobile networks that run IPv6-only with NAT64. The app works for nearly everyone else, so the bug sits in the backlog for months.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an IPv6-only network does
&lt;/h2&gt;

&lt;p&gt;On many carriers, the phone gets only an IPv6 address. There is no IPv4 route at all. To keep the IPv4 internet reachable, the carrier runs two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DNS64&lt;/strong&gt;: when the phone asks for a name that only has an IPv4 address (an &lt;code&gt;A&lt;/code&gt; record), the carrier's DNS server makes up an IPv6 address for it (an &lt;code&gt;AAAA&lt;/code&gt; record) by putting the IPv4 address inside a prefix, usually &lt;code&gt;64:ff9b::/96&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NAT64&lt;/strong&gt;: traffic to that made-up address goes to a gateway that translates it to IPv4 and back.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So anything that starts from a &lt;strong&gt;hostname&lt;/strong&gt; keeps working. Anything that starts from a raw &lt;strong&gt;IPv4 address&lt;/strong&gt; has nothing to resolve, nothing gets translated, and the connection fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An IPv4 literal anywhere in the app: &lt;code&gt;http://203.0.113.10/api&lt;/code&gt;, a fallback server list, a "connectivity check" against &lt;code&gt;8.8.8.8&lt;/code&gt;, a config file from the backend that hands out IPs instead of names.&lt;/li&gt;
&lt;li&gt;Code that checks the address family itself, such as rejecting anything that isn't &lt;code&gt;AF_INET&lt;/code&gt;, or parsing an address into four bytes.&lt;/li&gt;
&lt;li&gt;Old networking libraries, or C code, that call &lt;code&gt;gethostbyname&lt;/code&gt; (IPv4 only) instead of &lt;code&gt;getaddrinfo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Third-party SDKs that do any of the above. You only find these in a capture.&lt;/li&gt;
&lt;li&gt;Reachability checks against &lt;code&gt;0.0.0.0&lt;/code&gt; or an IPv4 address, which report "no network" on a network that works fine.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Apple tests for this
&lt;/h2&gt;

&lt;p&gt;App Review has required IPv6-only compatibility since 2016, and reviewers test on an IPv6-only network. "Cannot connect" rejections that nobody can reproduce in the office often come from this.&lt;/p&gt;

&lt;p&gt;You can build the same network on a Mac: hold Option, open &lt;strong&gt;System Settings &amp;gt; General &amp;gt; Sharing&lt;/strong&gt;, click the (i) next to &lt;strong&gt;Internet Sharing&lt;/strong&gt;, and turn on &lt;strong&gt;Create NAT64 Network&lt;/strong&gt;. Share the Mac's Ethernet connection over Wi-Fi, join that Wi-Fi from a test iPhone, and every IPv4 literal in the app fails the way it does for those users. (The Option key is what shows the NAT64 option. The menu layout changes between macOS versions, so search for "NAT64" if it isn't there.)&lt;/p&gt;

&lt;p&gt;On Android there's no built-in switch. The easiest reproduction is a real SIM on one of the IPv6-only carriers, or a test Wi-Fi network with only IPv6 and DNS64/NAT64 configured on the router. Android's own CLAT (464XLAT) translates IPv4 traffic on most IPv6-only mobile networks, which hides many of these bugs on Android but not all of them, and not on Wi-Fi.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fixes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use hostnames everywhere.&lt;/strong&gt; If a backend config hands out addresses, change it to hand out names. If you need a fixed address for some reason, give it a DNS name anyway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use the high-level APIs.&lt;/strong&gt; &lt;code&gt;URLSession&lt;/code&gt; and &lt;code&gt;Network.framework&lt;/code&gt; on iOS, OkHttp or &lt;code&gt;HttpURLConnection&lt;/code&gt; on Android. They resolve names with both families and use Happy Eyeballs to pick whichever connects first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If you must connect to a literal IPv4 address&lt;/strong&gt;, on iOS let &lt;code&gt;getaddrinfo&lt;/code&gt; turn it into a NAT64 address: pass the IPv4 string as the host with &lt;code&gt;AI_DEFAULT&lt;/code&gt; hints, and on an IPv6-only network you get back the synthesized IPv6 address. Then connect to whatever it returns, without checking the family.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove address-family checks.&lt;/strong&gt; Store addresses as strings or &lt;code&gt;sockaddr_storage&lt;/code&gt;, not as 4-byte integers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check reachability by doing the real request&lt;/strong&gt;, not by pinging an IPv4 address.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Finding the literals
&lt;/h2&gt;

&lt;p&gt;Search the code for IPv4 patterns, something like &lt;code&gt;grep -rEn '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' --include=*.swift --include=*.kt --include=*.java --include=*.m --include=*.json .&lt;/code&gt;, and skip the version numbers it also matches. Then use every screen of the app on the NAT64 network and watch its logs. A connection to a literal fails right away with "network unreachable" or a timeout, without any DNS lookup before it, which is also how you spot the ones inside third-party SDKs. Connections to &lt;code&gt;64:ff9b::&lt;/code&gt; addresses are fine: those are hostnames the network translated as intended.&lt;/p&gt;




&lt;p&gt;This article was created with the help of AI.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>android</category>
      <category>networking</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
