<?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: Kiran Kumar</title>
    <description>The latest articles on DEV Community by Kiran Kumar (@dkiran2323).</description>
    <link>https://dev.to/dkiran2323</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3976863%2F3793a8f3-7fe3-431e-a85b-1ba154bd90c1.png</url>
      <title>DEV Community: Kiran Kumar</title>
      <link>https://dev.to/dkiran2323</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dkiran2323"/>
    <language>en</language>
    <item>
      <title>How I Built a QR Code That Knows Whether You're on Android or iOS</title>
      <dc:creator>Kiran Kumar</dc:creator>
      <pubDate>Wed, 10 Jun 2026 07:56:35 +0000</pubDate>
      <link>https://dev.to/dkiran2323/how-i-built-a-qr-code-that-knows-whether-youre-on-android-or-ios-1e</link>
      <guid>https://dev.to/dkiran2323/how-i-built-a-qr-code-that-knows-whether-youre-on-android-or-ios-1e</guid>
      <description>&lt;p&gt;Here's the full article:&lt;/p&gt;

&lt;p&gt;How I Built a QR Code That Knows Whether You're on Android or iOS&lt;br&gt;
And the edge cases that almost broke it&lt;/p&gt;

&lt;p&gt;I was helping a client launch their mobile app. They had packaging printed — boxes, stickers, flyers — all with a QR code pointing to the Play Store.&lt;br&gt;
Then someone asked: "What about iPhone users?"&lt;br&gt;
We stared at each other.&lt;br&gt;
You can't print two QR codes on a box. You can't ask your customer to figure out which one to scan. And you definitely can't afford to lose half your potential installs because someone scanned the "wrong" code.&lt;br&gt;
That's the problem I set out to solve. The result is SingleQR — one QR code that detects whether you're on Android or iOS and redirects you to the right store automatically.&lt;br&gt;
Here's exactly how I built it.&lt;/p&gt;

&lt;p&gt;The Core Idea: Redirect at the URL Layer&lt;br&gt;
The QR code itself is just a URL. It doesn't know anything about the device scanning it — that's the job of the server.&lt;br&gt;
When someone scans the QR, they hit my redirect endpoint. At that point, I have one thing to work with: the HTTP User-Agent header.&lt;br&gt;
The flow looks like this:&lt;br&gt;
QR Scan&lt;br&gt;
  → HTTP GET to redirect.singleqr.in/{code}&lt;br&gt;
    → Read User-Agent header&lt;br&gt;
      → Android? → Play Store URL&lt;br&gt;
      → iOS?     → App Store URL&lt;br&gt;
      → Other?   → Fallback landing page&lt;br&gt;
Simple in theory. The edge cases are where it gets interesting.&lt;/p&gt;

&lt;p&gt;The Detection Logic&lt;br&gt;
Here's the core of the UA detection:&lt;br&gt;
javascriptfunction detectPlatform(userAgent) {&lt;br&gt;
  const ua = userAgent.toLowerCase();&lt;/p&gt;

&lt;p&gt;// iOS detection — must check before Android&lt;br&gt;
  // because some Android browsers include "like Mac OS X"&lt;br&gt;
  if (/iphone|ipad|ipod/.test(ua)) {&lt;br&gt;
    return 'ios';&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;// Android detection&lt;br&gt;
  if (/android/.test(ua)) {&lt;br&gt;
    return 'android';&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;// Everything else — desktop, unknown devices&lt;br&gt;
  return 'other';&lt;br&gt;
}&lt;br&gt;
Notice I check iOS before Android. This matters — some Android browser UAs contain phrases like "like Mac OS X" that can create false positives if you're not careful about order.&lt;/p&gt;

&lt;p&gt;Edge Case 1: iPads in Desktop Mode&lt;br&gt;
Since iOS 13, Safari on iPad defaults to desktop mode. This means the User-Agent no longer says "iPad" — it sends a macOS Safari UA instead.&lt;br&gt;
// Old iPad UA (iOS 12 and below)&lt;br&gt;
Mozilla/5.0 (iPad; CPU OS 12_0 like Mac OS X) AppleWebKit/605.1.15&lt;/p&gt;

&lt;p&gt;// New iPad UA (iOS 13+ with desktop mode ON — default)&lt;br&gt;
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15&lt;br&gt;
If you only check the UA, iPads on iOS 13+ will land on your desktop fallback page. That's a real miss.&lt;br&gt;
The fix: Check for the maxTouchPoints hint via a client-side script on the fallback page:&lt;br&gt;
javascript// On the fallback/desktop landing page&lt;br&gt;
if (navigator.maxTouchPoints &amp;gt; 1 &amp;amp;&amp;amp; /Macintosh/.test(navigator.userAgent)) {&lt;br&gt;
  // This is almost certainly an iPad in desktop mode&lt;br&gt;
  window.location.href = APP_STORE_URL;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Edge Case 2: Old Android WebViews Lying About Their UA&lt;br&gt;
Some old WebViews (particularly on Android 4.x) would send something like:&lt;br&gt;
Mozilla/5.0 (Linux; U; en-us) AppleWebKit/528.5+&lt;br&gt;
No "Android" in sight. These users hit the fallback page and get confused.&lt;br&gt;
The fix: Secondary signals — Accept-Language header, screen resolution, referrer chain. For most production use cases, the raw Android/iOS check covers 98%+ of scans. Log the ambiguous ones and review periodically.&lt;/p&gt;

&lt;p&gt;Edge Case 3: Huawei Devices Without the Play Store&lt;br&gt;
Post-2019, Huawei phones ship without Google Play Services. These devices do send Android UAs — but if you redirect them to the Play Store, the app won't be there.&lt;br&gt;
Detect Huawei specifically:&lt;br&gt;
javascriptfunction detectPlatform(userAgent) {&lt;br&gt;
  const ua = userAgent.toLowerCase();&lt;/p&gt;

&lt;p&gt;if (/iphone|ipad|ipod/.test(ua)) return 'ios';&lt;/p&gt;

&lt;p&gt;if (/android/.test(ua) &amp;amp;&amp;amp; (/huawei|honor|hms|emui/.test(ua))) {&lt;br&gt;
    return 'huawei'; // Route to AppGallery&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;if (/android/.test(ua)) return 'android';&lt;/p&gt;

&lt;p&gt;return 'other';&lt;br&gt;
}&lt;br&gt;
Or show a smart fallback page with both Play Store and AppGallery buttons — that's what SingleQR does by default.&lt;/p&gt;

&lt;p&gt;Edge Case 4: Bots and Crawlers&lt;br&gt;
Bots pollute your scan analytics and get confused by store redirects.&lt;br&gt;
javascriptconst BOT_PATTERNS = [&lt;br&gt;
  /googlebot/i, /bingbot/i, /slurp/i,&lt;br&gt;
  /facebot/i, /twitterbot/i, /whatsapp/i,&lt;br&gt;
];&lt;/p&gt;

&lt;p&gt;function isBot(userAgent) {&lt;br&gt;
  return BOT_PATTERNS.some(pattern =&amp;gt; pattern.test(userAgent));&lt;br&gt;
}&lt;br&gt;
For bots, serve a plain HTML page with Open Graph meta tags — so social share previews look good — without triggering a redirect.&lt;/p&gt;

&lt;p&gt;Performance: Getting Below 100ms&lt;br&gt;
The redirect needs to be fast. A user scanning a QR code has zero tolerance for a loading spinner.&lt;/p&gt;

&lt;p&gt;Edge functions (Cloudflare Workers) — UA parsing happens at the edge, close to the user&lt;br&gt;
No database lookup on the hot path — mappings are cached at the edge after the first request&lt;br&gt;
Simple 302 redirect — no JavaScript, no page load, just a header&lt;/p&gt;

&lt;p&gt;Result: median redirect time of ~65ms globally.&lt;br&gt;
javascriptexport default {&lt;br&gt;
  async fetch(request, env) {&lt;br&gt;
    const code = extractCode(request.url);&lt;br&gt;
    const mapping = await env.QR_CACHE.get(code);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!mapping) return Response.redirect('https://singleqr.in/not-found', 302);

const { androidUrl, iosUrl, fallbackUrl } = JSON.parse(mapping);
const ua = request.headers.get('User-Agent') || '';

if (isBot(ua)) return serveBotPage(mapping);

const platform = detectPlatform(ua);
const destination =
  platform === 'android' ? androidUrl :
  platform === 'ios'     ? iosUrl :
                           fallbackUrl;

return Response.redirect(destination, 302);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;What I'd Do Differently&lt;/p&gt;

&lt;p&gt;Build the analytics dashboard earlier. Turned out to be the feature clients ask about most.&lt;br&gt;
Handle iPad desktop mode from day one. Added it two weeks after launch after bug reports.&lt;br&gt;
Add a "test scan" button in the dashboard. Users want to verify their redirect works before printing 10,000 boxes.&lt;/p&gt;

&lt;p&gt;Try It&lt;br&gt;
If you're building an app and dealing with this problem, the tool is live at singleqr.in.&lt;br&gt;
Free tier available. Happy to answer questions in the comments — especially if you've hit UA detection edge cases I haven't covered.&lt;br&gt;
 #android #ios #webdev #showdev&lt;/p&gt;

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