<?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: Ahmed Ashour</title>
    <description>The latest articles on DEV Community by Ahmed Ashour (@ahmedashourdev).</description>
    <link>https://dev.to/ahmedashourdev</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%2F4207453%2F97b264bd-075d-44b0-89ab-299e2b5cea75.png</url>
      <title>DEV Community: Ahmed Ashour</title>
      <link>https://dev.to/ahmedashourdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmedashourdev"/>
    <language>en</language>
    <item>
      <title>Building a khatmah planner in React Native: a reading plan that recalculates instead of piling up debt</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Wed, 18 Nov 2026 10:03:01 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/building-a-khatmah-planner-in-react-native-a-reading-plan-that-recalculates-instead-of-piling-up-n41</link>
      <guid>https://dev.to/ahmedashourdev/building-a-khatmah-planner-in-react-native-a-reading-plan-that-recalculates-instead-of-piling-up-n41</guid>
      <description>&lt;p&gt;I build BetterMuslim, a React Native and Expo app for Muslim daily habits. This is about one feature in it, the khatmah planner: a plan to read the whole Qur'an mushaf (604 pages) by a date you choose. The code is plain TypeScript, and the interesting part was not the UI. It was three rules that are easy to get wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Most reading plans I tried work like a debt tracker. Miss three days and the app greets you with "you owe 60 pages". People close the app and never come back.&lt;/p&gt;

&lt;p&gt;I wanted the opposite:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The day's target recalculates from what is left, instead of piling up as a debt.&lt;/li&gt;
&lt;li&gt;A page only counts if it was actually read, not swiped past.&lt;/li&gt;
&lt;li&gt;Marking a day done must not break the streaks of every other habit in the app.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Rule 1: recalculate, don't accrue
&lt;/h2&gt;

&lt;p&gt;The plan is just a start date and a finish date. Today's target is whatever is left, spread over the days that remain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dailyTargetAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;KhatmahPlan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;readPages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Iterable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;todayKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;TOTAL_PAGES&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;readPages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// Past the finish date there are no days left to spread over; it is all due now.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;daysLeft&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;todayKey&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;finishDate&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;daysInclusive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;todayKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;finishDate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;daysLeft&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The headline stays "read these pages today". When the target grows past 1.75 times the original, the app offers to move the finish date instead. The suggested date has to actually put you back on the pace you chose, so it is computed from the original daily target, not by adding a few days:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;suggestedFinishDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;readPages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;todayKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;TOTAL_PAGES&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;readPages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;perDay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;originalDailyTarget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;daysNeeded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remaining&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;perDay&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;finish&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;toUTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;todayKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;daysNeeded&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;MS_PER_DAY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toISOString&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="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&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;Dates are compared as UTC midnights from &lt;code&gt;yyyy-MM-dd&lt;/code&gt; keys, so a daylight saving change cannot make a day 23 or 25 hours long and shift the count by one.&lt;/p&gt;

&lt;p&gt;Progress is a set of pages, not a high-water mark. If someone opens Al-Kahf on a Friday, that is reading, and it counts. So "Continue" opens the first unread page, and the juz bead ring only fills a bead when every page of that juz is read. A bead that filled on the first page would show 30 of 30 long before the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2: a page counts after 10 seconds
&lt;/h2&gt;

&lt;p&gt;If a page counted the moment it appeared, a fast swipe through the mushaf would finish a juz. So a page counts after it has been the visible page for 10 unbroken seconds, and backgrounding the app cancels it (a phone face down in a pocket is not reading):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;PAGE_DWELL_MS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;useEffect&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;countedRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;cancelled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;setTimeout&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;countedRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;KhatmahService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markPageRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;formatDateKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&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="no"&gt;PAGE_DWELL_MS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;appState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AppState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'change'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'active'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cancelled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timer&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cancelled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;appState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&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="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enabled&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 hook reads counted pages through a ref. The reader re-renders on every tap of its floating bar, and a re-render with the same page must not restart the timer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: don't change the global completion rule
&lt;/h2&gt;

&lt;p&gt;This was the one that cost me the most thought. Across the app, a counter habit is done at &lt;code&gt;value &amp;gt; 0&lt;/code&gt;. The khatmah habit needs to be done at the day's page target (say 21 pages), but changing the global rule would break the streak of every azkar habit sitting at 40 of 100 taps.&lt;/p&gt;

&lt;p&gt;My first idea was to special case the habit by checking whether a plan exists. That has a flaw: when falling behind raises today's target from 20 to 28, yesterday would be judged against 28 and a finished day would turn into a failed one. History would rewrite itself to look worse.&lt;/p&gt;

&lt;p&gt;So the target is written onto the day's own record, and the rule keys off the record:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isRecordValueComplete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Partial&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Pick&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SubHabitRecord&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'value'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s1"&gt;'target'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&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;Old records have no target, so they keep the old rule. A finished day keeps the target it carried. A missing, zero or nonsense target falls back to the old rule instead of locking the habit.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug the emulator found
&lt;/h2&gt;

&lt;p&gt;I tested on an Android emulator in Arabic. After reading one page the Home screen showed &lt;code&gt;1/8&lt;/code&gt; habits done, when it should have been &lt;code&gt;0/8&lt;/code&gt;. Home flattens each day into a &lt;code&gt;Record&amp;lt;string, boolean&amp;gt;&lt;/code&gt; with &lt;code&gt;Boolean(record.value)&lt;/code&gt; before the sections see it, so the target never reached the completion check. The fix was to decide completion where the record is still whole, which is why &lt;code&gt;isRecordValueComplete&lt;/code&gt; takes just the record and not the habit.&lt;/p&gt;

&lt;p&gt;Two self inflicted problems from the same session:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My new card mounted &lt;code&gt;useHabitsData()&lt;/code&gt;, which created a second live copy of the habits layer, fetching and syncing next to Home's. It hung the app. It now reads the cache once.&lt;/li&gt;
&lt;li&gt;Metro started returning 500 on its manifest endpoint. It was not my code. Fifteen orphaned &lt;code&gt;jest-worker&lt;/code&gt; processes from repeated test runs had used up process creation. Killing them fixed it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pace presets, and a Hijri edge case
&lt;/h2&gt;

&lt;p&gt;The pace sheet offers presets stored as a number of days: one page a day (604 days), a page after each prayer (&lt;code&gt;ceil(604 / 5)&lt;/code&gt;), half a juz, a juz a day (30), 15 days, a week. There is also a Ramadan pace: during Ramadan it means finish by Eid, otherwise finish before the next Ramadan.&lt;/p&gt;

&lt;p&gt;I did not compute that date arithmetically. Hijri months are 29 or 30 days depending on the calendar, so the code walks forward one day at a time, converts each date, and stops at the first day whose month changes. The finish date is shown on the option, so someone whose country sights the moon a day apart sees it before choosing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I would have written the Supabase migration and run it before the client code. The reading plan tables, row level security and the new &lt;code&gt;target&lt;/code&gt; column on the daily records exist as a migration, but I had no Docker on that machine, so sync was untested when I wrote this up. Everything worked from local storage first, which is the right order for the user, but I should have validated the schema sooner.&lt;/li&gt;
&lt;li&gt;I wrote 37 new tests before the code, and the plan arithmetic is pure, so it runs without a device. I would do the same for the Home flattening, where the bug actually was. A test on that path would have caught the &lt;code&gt;1/8&lt;/code&gt; without an emulator.&lt;/li&gt;
&lt;li&gt;I only built three paces first (30 days, a juz a day, 15 days) and added the rest later. People plan by pages or by a deadline, so I would have started with that fuller list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are building habit tracking, my main takeaway is to attach the rule to the record, not to the habit. It keeps history stable when the rules change.&lt;/p&gt;

&lt;p&gt;BetterMuslim is my own app, if you want to see the khatmah planner in use: &lt;a href="https://bettermuslim.net/?ref=devto" rel="noopener noreferrer"&gt;bettermuslim.net&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>typescript</category>
      <category>mobile</category>
      <category>ios</category>
    </item>
    <item>
      <title>Most of my Android "purchase errors" were Google's test phones</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Sat, 07 Nov 2026 07:43:59 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/most-of-my-android-purchase-errors-were-googles-test-phones-1hb1</link>
      <guid>https://dev.to/ahmedashourdev/most-of-my-android-purchase-errors-were-googles-test-phones-1hb1</guid>
      <description>&lt;p&gt;I build a few mobile apps on the side. One of them is a German citizenship test prep app, on iPhone and Android, with a paywall and RevenueCat for purchases.&lt;/p&gt;

&lt;p&gt;Last week Android looked broken. The funnel said people opened the paywall, tried to buy, and got billing errors. iPhone was fine. I was about to go digging in the billing code.&lt;/p&gt;

&lt;p&gt;Then I looked at who was producing the errors. Most of them were not people.&lt;/p&gt;

&lt;h2&gt;
  
  
  Google's test phones
&lt;/h2&gt;

&lt;p&gt;When you upload an Android build to Google Play, Google can run a pre-launch report: it installs your app on a set of test devices, taps around, and sends you a report. Those devices are real sessions as far as your SDK is concerned. They open the app, they reach the paywall, and they try things.&lt;/p&gt;

&lt;p&gt;In my data they were easy to see once I looked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The device model starts with &lt;code&gt;sdk_gphone&lt;/code&gt; (the Android emulator), or it is a model that no real user of my app has.&lt;/li&gt;
&lt;li&gt;Mostly Android 11, the same emulator model every time, always an English locale.&lt;/li&gt;
&lt;li&gt;A US IP address, even though the app is for people in Germany.&lt;/li&gt;
&lt;li&gt;A burst of sessions around the same minute, and the device never comes back.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm only describing what I saw in my own data. I can't promise it is how every pre-launch device looks, so check yours before you filter on it. The model name is the part I would trust most.&lt;/p&gt;

&lt;p&gt;Billing on these devices fails. RevenueCat returns "device or user is not allowed to make the purchase". Every time a test phone opens the paywall and taps buy, you get a purchase error.&lt;/p&gt;

&lt;p&gt;On one busy day, test phones made all of the purchase errors in that app. A real user had nothing to do with them.&lt;/p&gt;

&lt;p&gt;Apple has the same thing. Review runs your build too, usually as a US iPhone on a version that is not live yet. It belongs in the same filter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why leave them out of funnels
&lt;/h2&gt;

&lt;p&gt;A funnel only works if each step is a person deciding something. Test phones break that in two ways.&lt;/p&gt;

&lt;p&gt;They add people who were never going to buy. That pushes your conversion down. And they create errors that no real person saw. That makes a healthy payment flow look broken.&lt;/p&gt;

&lt;p&gt;Mine did both. Android's paywall looked like it had a billing problem, so I wanted to spend a day on it. The problem was in my analytics, not the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the numbers looked like after
&lt;/h2&gt;

&lt;p&gt;I excluded the test devices and counted again. Of the Android people who saw the paywall, about 1 in 40 tapped buy. On iPhone it was about 1 in 9.&lt;/p&gt;

&lt;p&gt;That is a real gap, and it is a very different problem from "Android billing is broken". The first one is a story about the paywall, the price in local currency, or who uses Android for this kind of app. The second would have sent me into the wrong code.&lt;/p&gt;

&lt;p&gt;I don't know yet why Android is lower. I have ideas, and I'll test them one at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The real bug the filter uncovered
&lt;/h2&gt;

&lt;p&gt;With the noise gone, one thing stood out. A real user had tapped buy 12 times, and I had nothing logged for any of them. Not a success, not an error.&lt;/p&gt;

&lt;p&gt;So I read the purchase code. There was a path where the purchase call returned, but the entitlement was not active yet, and the function simply ended. No message, no event, no alert. From the user's side, they tapped buy and nothing happened, so they tapped again.&lt;/p&gt;

&lt;p&gt;That was the silent "no entitlement" path. It was my bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: log every outcome
&lt;/h2&gt;

&lt;p&gt;Every purchase attempt should end in exactly one named outcome, and the user should always see something. These are the four I use: &lt;code&gt;unlocked&lt;/code&gt;, &lt;code&gt;no_entitlement&lt;/code&gt;, &lt;code&gt;cancelled&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is the shape of it, in TypeScript with a RevenueCat-style API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Outcome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unlocked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no_entitlement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;buying&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;buy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pkg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Package&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;buying&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// guard double taps&lt;/span&gt;
  &lt;span class="nx"&gt;buying&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;purchase_tapped&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pkg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;identifier&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// if nothing has finished after 20s, say so&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pending&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;purchase_pending&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;finish&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Outcome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pending&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;buying&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;purchase_outcome&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;extra&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;customerInfo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;purchasePackage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pkg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;customerInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;entitlements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pro&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unlocked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;no_entitlement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;Alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Almost there&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The purchase went through but Pro is not active yet. Tap Restore, or try again in a minute.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userCancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cancelled&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;Alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Purchase failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nothing was charged. Please try again.&lt;/span&gt;&lt;span class="dl"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The details that matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One outcome per attempt.&lt;/strong&gt; If you can't tell which of the four happened, a funnel step is hiding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No silent path.&lt;/strong&gt; The &lt;code&gt;no_entitlement&lt;/code&gt; branch used to be a bare return. Now it logs and shows an alert.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Guard double taps.&lt;/strong&gt; If the first tap is still running, the second one does nothing. Before this, 12 taps were 12 calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A pending event after 20 seconds.&lt;/strong&gt; Slow billing is not an error and not a success. Without this event you can't see it at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep the error code and message in the event. They are how you tell "device not allowed" from a real failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to do this in your own data
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Add the device model to your events if your SDK doesn't. In my case the iOS SDK did not send the model at all, so I couldn't filter iPhone test devices by model and had to go by app version.&lt;/li&gt;
&lt;li&gt;Look at purchase errors grouped by device model. If a model like &lt;code&gt;sdk_gphone...&lt;/code&gt; is on top, you've found them.&lt;/li&gt;
&lt;li&gt;Check the pre-launch report in Play Console for the exact devices it used, and compare with what you see.&lt;/li&gt;
&lt;li&gt;Filter the same way in every chart: funnels, retention, error counts. Doing it in one chart and not another gives you two numbers that disagree.&lt;/li&gt;
&lt;li&gt;Re-run your funnel and read the ratios, not the totals.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Disclosure
&lt;/h2&gt;

&lt;p&gt;I build Apparent, which leaves Google's and Apple's test phones out of every number by default. If you want to try it, it's at &lt;a href="https://apparent.fyi/?ref=devto" rel="noopener noreferrer"&gt;apparent.fyi&lt;/a&gt;. The same filter works if you do it by hand, and the code above doesn't need it.&lt;/p&gt;

&lt;p&gt;The part I'd keep even if you never use a tool: log every outcome, and never let a purchase end without telling the user something.&lt;/p&gt;

</description>
      <category>android</category>
      <category>reactnative</category>
      <category>analytics</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Reading ingredient lists from phone photos: a crop bug, a model bench, and why the AI never gives the verdict</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Mon, 02 Nov 2026 19:38:50 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/reading-ingredient-lists-from-phone-photos-a-crop-bug-a-model-bench-and-why-the-ai-never-gives-4bc9</link>
      <guid>https://dev.to/ahmedashourdev/reading-ingredient-lists-from-phone-photos-a-crop-bug-a-model-bench-and-why-the-ai-never-gives-4bc9</guid>
      <description>&lt;p&gt;I build Halal Food Scanner, an iPhone and Android app (Expo / React Native) that tells you if a food is halal. You scan the barcode, and when the product isn't in Open Food Facts or has no ingredient list there, you take a photo of the ingredients instead. The app answers Halal, Haram or Uncertain, with the reason for each ingredient.&lt;/p&gt;

&lt;p&gt;The photo path is where most of the hard work is. This is what we learned building it, including a bug I shipped myself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The model reads, a table rules
&lt;/h2&gt;

&lt;p&gt;The first decision was the most important one: the AI does not decide if something is halal.&lt;/p&gt;

&lt;p&gt;A photo goes to a vision model in one call. The model has one job: find the ingredient names on the pack and map each one to an id in our own table ("Gelatine" -&amp;gt; gelatin, "E471" / "mono- and diglycerides of fatty acids" -&amp;gt; e471, "Lab" -&amp;gt; rennet). The verdict comes from the table, not from the model.&lt;/p&gt;

&lt;p&gt;The table is a human-reviewed list of 401 E-numbers (261 halal, 138 uncertain, 2 haram) plus named ingredients like gelatin, rennet, whey and natural flavourings. Each row is sourced to halal bodies and standards (JAKIM MS 1500, IFANCA, SANHA, MUI and others). Where they disagree, the app follows the most cautious reviewed position and shows the others.&lt;/p&gt;

&lt;p&gt;Two rules fall out of this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If an ingredient can come from a halal or a non-halal source and the pack doesn't say which (gelatin, E471, whey), the answer is &lt;strong&gt;Uncertain&lt;/strong&gt;, not a guess.&lt;/li&gt;
&lt;li&gt;If the model finds a word that isn't in the table, the answer for that word is &lt;strong&gt;Not checked&lt;/strong&gt;. A gap is never shown as a pass.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why so strict? Because when we benched models on real photos, some of them invented ingredients. On a 30-photo bench of Japanese and French packs, one model added ingredients that weren't on the pack at all. A small, fast model did the same on other labels. In a halal app an invented ingredient is a wrong answer, so the model only gets the part of the job where a mistake is visible and checkable: reading.&lt;/p&gt;

&lt;p&gt;We now send photos to Gemini Flash first and only fall back to other models when it fails or times out. For blurry, sideways Arabic labels, an empty read gets one retry with the stronger model.&lt;/p&gt;

&lt;h2&gt;
  
  
  The crop that cut the ingredients out
&lt;/h2&gt;

&lt;p&gt;At the time, ML Kit ran a quick text check on the phone before we uploaded anything. It told us if the photo had readable text at all, so we could ask for a retake right away instead of after a network round trip.&lt;/p&gt;

&lt;p&gt;On October 15 I made what looked like a smart change: ML Kit already knows where the text is, so crop the upload to that text box. Smaller image, bigger letters, better reads. We were sending the photo at 1024 px on the long edge, so the crop should help small print.&lt;/p&gt;

&lt;p&gt;It didn't. After the change, the share of ingredient photos that came back with no ingredients went from about 40% to 48%.&lt;/p&gt;

&lt;p&gt;The reason only showed up when I looked at the photos. Since mid-October the app keeps failed ingredient photos for 30 days in a private bucket, so we can check failures by hand. Two things were in there:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sideways photos.&lt;/strong&gt; People hold the pack however it comes off the shelf. On a sideways photo, the box ML Kit drew was often around the brand name or the nutrition table, and the ingredient list was outside the crop. The model got a clean picture of the wrong text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Our own test shots.&lt;/strong&gt; A good chunk of the "empty" photos were us: a desk, an icon, a hand. Without looking, I would have blamed users for bad photos and moved on.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The fix was to stop cropping. The whole frame now goes up at 1600 px instead of 1024. On a bench of 8 full-resolution Open Food Facts photos, 7 read the same and one small multilingual label went from 4 lumped strings to 18 separate ingredients. The cost is about 0.8 s more per read (median ~3.8 s -&amp;gt; ~4.6 s), which is fine for a photo you take once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then we removed the on-device check too
&lt;/h2&gt;

&lt;p&gt;Two weeks later the same kind of look at the data killed the ML Kit check completely. A third of ingredients scans took 2 or 3 shots because ML Kit judged the photo unreadable, and Arabic and Japanese labels always used all three, even though the cloud model reads them fine. Median capture time was 4.6 s with retakes against 1.9 s for one shot. Now the app sends the first photo straight away, and the native module is gone from the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the user sees when it fails
&lt;/h2&gt;

&lt;p&gt;The old app showed an error alert when a photo came back empty. Now it shows a small picture sheet: wrong side of the pack, too blurry, and from the first miss a button to scan the barcode instead. Showing a picture of a good ingredients photo works better than any sentence we wrote.&lt;/p&gt;

&lt;p&gt;This matters more than it looks. People whose first day gave them an answer came back on another day 38% of the time. People who got no answer came back 10% of the time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone reading text from photos with an LLM
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep the model's job small.&lt;/strong&gt; Let it read and map to ids you control. Put the decision in data you can review and test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unknown is an answer.&lt;/strong&gt; "Uncertain" and "Not checked" are better than a confident guess, and users understand them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep failed inputs and look at them.&lt;/strong&gt; With care (private storage, short retention), but look. Our metric said users take bad photos. The photos said I shipped a bug.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be careful with optimizations that trim the input.&lt;/strong&gt; A crop, a downscale, a token limit: each one can quietly remove the thing you needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see the rulings the table uses, they're public on the site, for example &lt;a href="https://halalfoodscanner.app/ingredients/e471/" rel="noopener noreferrer"&gt;is E471 halal?&lt;/a&gt; and the &lt;a href="https://halalfoodscanner.app/ingredients/" rel="noopener noreferrer"&gt;full E-number list&lt;/a&gt;. The app is at &lt;a href="https://halalfoodscanner.app/" rel="noopener noreferrer"&gt;halalfoodscanner.app&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>machinelearning</category>
      <category>mobile</category>
      <category>ai</category>
    </item>
    <item>
      <title>Building an MCP server for app analytics, so Claude can tell me how my apps are doing</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Mon, 02 Nov 2026 19:13:45 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/building-an-mcp-server-for-app-analytics-so-claude-can-tell-me-how-my-apps-are-doing-4p1m</link>
      <guid>https://dev.to/ahmedashourdev/building-an-mcp-server-for-app-analytics-so-claude-can-tell-me-how-my-apps-are-doing-4p1m</guid>
      <description>&lt;p&gt;I build a few mobile apps on the side, and I built my own analytics for them, &lt;a href="https://apparent.fyi/?ref=devto" rel="noopener noreferrer"&gt;Apparent&lt;/a&gt;. It reads App Store Connect, Google Play, RevenueCat and its own SDK, and turns them into plain sentences.&lt;/p&gt;

&lt;p&gt;I spend most of the day in Claude Code anyway. So I wanted to ask it "how are my apps doing?" or "why did downloads drop on Tuesday?" without opening a dashboard. That's what MCP is for: a small server that gives the agent tools it can call.&lt;/p&gt;

&lt;p&gt;The first version was small: four read-only tools. Making it answer well took longer. These are the things that mattered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Answer in sentences, not rows
&lt;/h2&gt;

&lt;p&gt;I already had a command line tool, &lt;code&gt;apparent&lt;/code&gt;, that answers in sentences. The MCP tools call the same answer functions, so the agent and the terminal say the same thing.&lt;/p&gt;

&lt;p&gt;I kept sentences on purpose. App numbers come with a lot of small print: store data arrives one or two days late, so today never has downloads yet. Google's pre-launch test phones and Apple's review are not real people. Money is what you keep after the store's cut. If the agent gets raw rows, it has to know all of that. If it gets a sentence, the small print is already in it.&lt;/p&gt;

&lt;p&gt;So the server's instructions end with one rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;INSTRUCTIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apparent is the analytics for your mobile apps ... &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Every tool is read-only and answers in plain words; quote its wording. &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Test phones (Google's pre-launch phones, Apple's review) are never counted. &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Store numbers arrive 1–2 days late, so 'today' has no downloads yet. ...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Quote its wording" does a lot. Without it the agent rewrites the answer and the caveats fall off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then add JSON, both ways
&lt;/h2&gt;

&lt;p&gt;Sentences are great to read, but sometimes the agent wants to do something with the numbers: make a chart, compare two apps, write a note in a PR.&lt;/p&gt;

&lt;p&gt;The newer tools return three things: the sentence, a compact JSON copy as a second text block, and the same JSON as &lt;code&gt;structuredContent&lt;/code&gt;. The copy in text is there because some clients only read text content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;withJson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Answer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt;
  &lt;span class="na"&gt;structuredContent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;json&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 older tools stay text only. Their JSON is the whole page and it's too big for one reply.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep output schemas open
&lt;/h2&gt;

&lt;p&gt;This one is easy to miss. If a tool declares an &lt;code&gt;outputSchema&lt;/code&gt;, clients like Claude Code and the official SDK check the reply against it, and a key the schema doesn't list makes the call fail.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;today&lt;/code&gt; tool answers with more keys for all apps together than for one app. So every output schema is an open object, and only the keys I promise are listed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ZodRawShape&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;looseObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nl"&gt;outputSchema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;out&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="na"&gt;live&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="na"&gt;now&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;number&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;h2&gt;
  
  
  stdout belongs to the protocol
&lt;/h2&gt;

&lt;p&gt;The local version runs over stdio. Anything your code prints to stdout lands in the middle of the JSON-RPC stream and breaks it. My answer functions log here and there, so the server sends every &lt;code&gt;console.log&lt;/code&gt; to stderr before it starts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// stdout is the protocol: anything the answers print goes to stderr instead.&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;debug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loading the answers also opens the database, which is slow. So the server imports them the first time a tool is called, not at start. The agent sees the server come up right away.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tool description is the prompt
&lt;/h2&gt;

&lt;p&gt;The agent picks a tool by its description, so I write descriptions as "use this when". The one for explaining changes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use whenever someone asks why a number moved: a spike, a drop, a quiet or busy day ('why did downloads spike on Sep 21?').&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And the answer format is in the description too: each cause says how much of the number it explains ("Apple Ads 83 of 147"), whether a store counted it or it's worked out ("about"), what nothing explains, how sure the whole answer is (sure, likely, guess), and at most one next step. When the agent knows that shape, it passes it on instead of guessing.&lt;/p&gt;

&lt;p&gt;One small trick: the &lt;code&gt;app&lt;/code&gt; argument lists the known apps in its description, and accepts part of a name. So "how is the halal app doing" just works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Going remote: stateless HTTP
&lt;/h2&gt;

&lt;p&gt;For other people, the server also runs over Streamable HTTP. I made it stateless: every POST gets its own server and transport, the answer is plain JSON, and there are no sessions to keep.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;newServer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;registerTools&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;transport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WebStandardStreamableHTTPServerTransport&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;sessionIdGenerator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;enableJsonResponse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;transport&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;transport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handleRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GET and DELETE answer 405, which the spec allows for a server that never starts a stream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tokens, and the 401 I got wrong
&lt;/h2&gt;

&lt;p&gt;Each person makes a token on the Connect page. It's stored only as a sha256 hash, it can only read, and it only reaches &lt;code&gt;/mcp&lt;/code&gt; and the read-only GET routes. Never a write, never the setup routes that hold webhook secrets. Each token is rate limited (120 a minute, 2,000 an hour), and wrong tokens are limited per address.&lt;/p&gt;

&lt;p&gt;My first version sent anyone without a session to the login page with a redirect. Fine for a browser, wrong for MCP. Clients and directory health checks expect a 401 that says how to authenticate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/mcp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WWW-Authenticate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bearer realm="Apparent", error="invalid_token", error_description="Make a token on the Connect page under Your agents"&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Add a token: Authorization: Bearer apt_…, made on the Connect page under Your agents.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;401&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;Adding it to Claude Code is one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add &lt;span class="nt"&gt;--scope&lt;/span&gt; user &lt;span class="nt"&gt;--transport&lt;/span&gt; http apparent https://app.apparent.fyi/mcp &lt;span class="nt"&gt;--header&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: Bearer &amp;lt;your token&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Getting it listed
&lt;/h2&gt;

&lt;p&gt;I published it to the official MCP Registry as &lt;code&gt;fyi.apparent/apparent&lt;/code&gt;, a remote server with a required Authorization header. The domain is proven with a DNS TXT record on apparent.fyi, so nobody else can publish under that name. Several directories read from the registry, so one publish covered them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I ask it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;"How are my apps doing?" One or two sentences per app for the last 7 days.&lt;/li&gt;
&lt;li&gt;"How is today going?" People so far against a usual day at this same hour.&lt;/li&gt;
&lt;li&gt;"Why did downloads go up on the 21st?" Causes with how much each one explains.&lt;/li&gt;
&lt;li&gt;"Did yesterday's update help?" Before and after, in words.&lt;/li&gt;
&lt;li&gt;"What should I fix next?" It reads the crashes and where people stop, then opens the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last one is the reason I built it. The agent that knows the code now also knows what people do with it.&lt;/p&gt;

&lt;p&gt;If you want to try it with your own apps, the MCP page is at &lt;a href="https://apparent.fyi/app-analytics-mcp?ref=devto" rel="noopener noreferrer"&gt;apparent.fyi/app-analytics-mcp&lt;/a&gt;. Apparent is simple analytics that celebrates your app's small wins.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>mobile</category>
      <category>analytics</category>
    </item>
    <item>
      <title>What I learned shipping a fully RTL Arabic app with React Native and Expo</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Mon, 02 Nov 2026 16:00:53 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/what-i-learned-shipping-a-fully-rtl-arabic-app-with-react-native-and-expo-f14</link>
      <guid>https://dev.to/ahmedashourdev/what-i-learned-shipping-a-fully-rtl-arabic-app-with-react-native-and-expo-f14</guid>
      <description>&lt;p&gt;I build BetterMuslim, a free Islamic habit app, with React Native and Expo. It's in six languages, and one of them is Arabic with the whole layout mirrored. About 1 in 4 people who tick a habit in it use it in Arabic, so RTL isn't an extra for me.&lt;/p&gt;

&lt;p&gt;RTL in React Native looks like one flag. It isn't. These are the bugs I shipped and how I fixed them.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. One source of truth: I18nManager.forceRTL
&lt;/h2&gt;

&lt;p&gt;The language is picked in the app, not taken from the phone. Arabic sets &lt;code&gt;I18nManager.forceRTL(true)&lt;/code&gt;, and that only takes effect after a full reload. So the app reloads itself once when the language changes, and once at startup if the saved native flag doesn't match the app language. A key in storage makes sure it can never restart in a loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;syncNativeRTLOnStartup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldBeRTL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;I18nManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRTL&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;shouldBeRTL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;AsyncStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RTL_RELOAD_GUARD_KEY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;I18nManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;allowRTL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldBeRTL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;I18nManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forceRTL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldBeRTL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;attemptedFor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;AsyncStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RTL_RELOAD_GUARD_KEY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;attemptedFor&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldBeRTL&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// already tried, no restart loop&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;AsyncStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RTL_RELOAD_GUARD_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldBeRTL&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;reloadAppForRTL&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Updates.reloadAsync() on iOS, react-native-restart on Android&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. A config key that undid it on every launch
&lt;/h2&gt;

&lt;p&gt;For a while the Arabic UI on iOS was half mirrored. The cause: with &lt;code&gt;supportsRTL&lt;/code&gt; in the Expo config, expo-localization's iOS module rewrote the RTL flag from the &lt;em&gt;device&lt;/em&gt; language on every launch. Arabic in the app on an English iPhone got overwritten each time. I removed the key from the config, Info.plist and Android strings. It's a native change, so it needs a new build, an OTA update won't fix it.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Stop flipping styles yourself
&lt;/h2&gt;

&lt;p&gt;Once the native mirroring actually worked, every &lt;code&gt;isRTL ? 'right' : 'left'&lt;/code&gt; in the code flipped things a second time and put them back on the wrong side.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;forceRTL&lt;/code&gt; on, the engine already mirrors &lt;code&gt;flexDirection: 'row'&lt;/code&gt;, &lt;code&gt;start&lt;/code&gt;/&lt;code&gt;end&lt;/code&gt;, &lt;code&gt;left&lt;/code&gt;/&lt;code&gt;right&lt;/code&gt;, &lt;code&gt;alignSelf&lt;/code&gt; and &lt;code&gt;textAlign&lt;/code&gt; (&lt;code&gt;swapLeftAndRightInRTL&lt;/code&gt; is on by default). So now every style is written LTR first: plain &lt;code&gt;row&lt;/code&gt;, &lt;code&gt;marginStart&lt;/code&gt;, &lt;code&gt;textAlign: 'left'&lt;/code&gt; meaning "start". The only places that still read &lt;code&gt;isRTL&lt;/code&gt; are the things the engine doesn't mirror: icon transforms, the Arabic font and size, and Arabic numerals.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Always set textAlign
&lt;/h2&gt;

&lt;p&gt;With no &lt;code&gt;textAlign&lt;/code&gt;, Fabric uses "natural" alignment, and natural follows the phone's language, not your app's. Arabic text was left aligned on English iPhones. The app's base text component now always sets &lt;code&gt;textAlign: 'left'&lt;/code&gt; (which is "start" and gets mirrored). For Arabic scripture that must sit on the right in both app languages, I use &lt;code&gt;writingDirection: 'rtl'&lt;/code&gt; and no &lt;code&gt;textAlign&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Modals don't inherit the direction
&lt;/h2&gt;

&lt;p&gt;On the new architecture a &lt;code&gt;Modal&lt;/code&gt;'s content lays out as its own LTR island. Everything inside was left to right in Arabic. I wrap &lt;code&gt;Modal&lt;/code&gt; in a small component that sets an explicit &lt;code&gt;direction&lt;/code&gt; on its content.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Physical coordinates must opt out
&lt;/h2&gt;

&lt;p&gt;The Quran reader shows the mushaf as page images: 604 pages in the printed Madani layout people know, with the same line breaks and page ends. To tap and highlight an ayah, an overlay draws rectangles from the page image's own pixel grid.&lt;/p&gt;

&lt;p&gt;Under &lt;code&gt;forceRTL&lt;/code&gt;, Fabric rewrites every &lt;code&gt;left&lt;/code&gt; in the tree to &lt;code&gt;start&lt;/code&gt;, which in Arabic is the physical right. Every highlight moved onto the neighbouring ayah. Touches were fine because &lt;code&gt;locationX&lt;/code&gt; is physical, so the right ayah was selected and the wrong place was painted. Tests that only checked the selection passed.&lt;/p&gt;

&lt;p&gt;The fix is &lt;code&gt;direction: 'ltr'&lt;/code&gt; on anything measured against an image, a canvas or a pixel grid (plus a &lt;code&gt;dir="ltr"&lt;/code&gt; prop for react-native-web, which reads the prop, not the style). Same for the khatmah ring of 30 beads, which otherwise put juz 1 where juz 30 belongs.&lt;/p&gt;

&lt;p&gt;About the page images: React Native's &lt;code&gt;Image&lt;/code&gt; only keeps a small memory cache, so every page turn was a new download, even going back one page. Now each page is saved to the documents folder once, 4 pages ahead and 2 behind are fetched while you read, and the whole mushaf can be saved for offline reading (about 75 MB).&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Arabic typography traps
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The missing hamza.&lt;/strong&gt; I went through the app looking for Arabic spelling mistakes and found أنجزت showing as انجزت and القرآن as القران. The strings were right. The font (Cairo) was being clipped: its baseline sits 0.57em above the bottom of the line, so with a line height of about 1.3em only 0.73em is left above it, and the hamza on أ reaches 0.96em. ؤ and إ survived, which was the tell. Arabic text now gets a line height of at least 1.6 times the font size. Before you fix Arabic "spelling", compare the source string with the screen and render it with &lt;code&gt;hb-view&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Letter spacing.&lt;/strong&gt; Negative &lt;code&gt;letterSpacing&lt;/code&gt; breaks Arabic shaping on Android. Words stacked one per line. Arabic gets &lt;code&gt;letterSpacing: 0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numbers inside Arabic lines.&lt;/strong&gt; React Native on iOS ignores bidi isolate characters. An ayah reference like 37:100-107 in an Arabic line came out as ١٠٧-٣٧:١٠٠. Arabic references are now written as surah name and range: سورة الصافات ١٠٠-١٠٧.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quran text and the font.&lt;/strong&gt; The Amiri Quran font is drawn for the Tanzil Uthmani text. Text from another source used a different character for the small yeh, and إبراهيم came out wrong. Ayahs are now copied by verse key from Tanzil Uthmani, and every quoted ayah gets rendered and checked before it ships.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plurals.&lt;/strong&gt; Arabic day counts need different words (يومين، أيام، يومًا). Pick the plural from the number before you format it into Arabic digits, not after.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Smaller ones
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Never put &lt;code&gt;scaleX: -1&lt;/code&gt; directly on an SVG icon (lucide). On Android under RTL it disappears, because the SVG root scales around its top left corner and the glyph leaves its box. Put the transform on a wrapping &lt;code&gt;View&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Padding belongs on a ScrollView's &lt;code&gt;contentContainerStyle&lt;/code&gt;, not its &lt;code&gt;style&lt;/code&gt;. Under RTL, padding on &lt;code&gt;style&lt;/code&gt; rendered the content off centre and clipped at the screen edge.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. You can't test RTL in a browser
&lt;/h2&gt;

&lt;p&gt;react-native-web hard-codes &lt;code&gt;I18nManager.isRTL&lt;/code&gt; to false, and its &lt;code&gt;forceRTL()&lt;/code&gt; does nothing. Two of the bugs above passed a full Playwright suite and shipped. Anything that depends on direction needs a device in Arabic. On the iOS simulator, switching to RTL needs a cold restart.&lt;/p&gt;

&lt;p&gt;If you want to see how it ended up, the app is &lt;a href="https://bettermuslim.net/" rel="noopener noreferrer"&gt;BetterMuslim&lt;/a&gt;, and the site has an &lt;a href="https://bettermuslim.net/ar/" rel="noopener noreferrer"&gt;Arabic version&lt;/a&gt; too. If you've hit an RTL bug that isn't here, I'd like to hear it.&lt;/p&gt;

</description>
      <category>mobile</category>
      <category>reactnative</category>
      <category>i18n</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Building a Fajr alarm that keeps ringing until you're up: AlarmKit, backup rings and an on-device prayer mat check</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Mon, 02 Nov 2026 15:57:03 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/building-a-fajr-alarm-that-keeps-ringing-until-youre-up-alarmkit-backup-rings-and-an-on-device-2h5</link>
      <guid>https://dev.to/ahmedashourdev/building-a-fajr-alarm-that-keeps-ringing-until-youre-up-alarmkit-backup-rings-and-an-on-device-2h5</guid>
      <description>&lt;p&gt;I build BetterMuslim, a free Islamic habit app for iOS and Android. Fajr, the dawn prayer, is the one people miss most, and most of the time it isn't a lack of will, it's the snooze button. So I built an alarm that rings at Fajr and keeps coming back until you show you're up: you read a short du'a aloud, or you take a photo of your prayer mat.&lt;/p&gt;

&lt;p&gt;This is how it works under the hood, and what broke on real phones.&lt;/p&gt;

&lt;h2&gt;
  
  
  A real alarm on iOS: AlarmKit
&lt;/h2&gt;

&lt;p&gt;Before iOS 26 an app could only send notifications. They don't ring with the silent switch on, and one notification is one short sound. iOS 26 added AlarmKit, which lets an app book real system alarms that ring on silent, like the Clock app.&lt;/p&gt;

&lt;p&gt;Booking one looks like this (trimmed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;alert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;AlarmPresentation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Fajr"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;stopButton&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;secondaryButton&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wake&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// "I'm up"&lt;/span&gt;
  &lt;span class="nv"&gt;secondaryButtonBehavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;custom&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;AlarmManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;AlarmConfiguration&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;FajrAlarmMetadata&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nv"&gt;countdownDuration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nv"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nv"&gt;attributes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;AlarmAttributes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;presentation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;AlarmPresentation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;tintColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;gold&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nv"&gt;stopIntent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;FajrStopIntent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alarmID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuidString&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nv"&gt;secondaryIntent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;FajrWakeIntent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;alarmID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuidString&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nv"&gt;sound&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sound&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="kt"&gt;AlarmManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sound is one ayah from the reciter the person picked in the app. AlarmKit plays sounds by name from &lt;code&gt;Library/Sounds&lt;/code&gt;, it doesn't take MP3, and past about 30 seconds it falls back to its own tone. So the app downloads the recitation, decodes it to 16-bit PCM, writes a CAF file and cuts it at 29 seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Stop button problem
&lt;/h2&gt;

&lt;p&gt;AlarmKit always shows a Stop button and you can't hide it. You also can't count on the Stop intent running: in my testing it was skipped when the alarm was dismissed with the phone unlocked, and on the simulator App Intents couldn't find my intent types at all.&lt;/p&gt;

&lt;p&gt;So I stopped relying on Stop. Each Fajr alarm is booked as a first ring plus a run of backup rings. Stop silences one ring, and the next one is already booked. Only the proof (the du'a or the photo) cancels the rest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;bookWindow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="nv"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="nv"&gt;booked&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;inout&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="kt"&gt;FajrWakeState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backups&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;fire&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addingTimeInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="kt"&gt;FajrWakeState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backupGap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;UUID&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;book&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fire&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;booked&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuidString&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fire&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timeIntervalSince1970&lt;/span&gt;
    &lt;span class="kt"&gt;FajrWakeState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;booked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;booked&lt;/span&gt;   &lt;span class="c1"&gt;// saved after each booking, not at the end&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;What I learned here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save every alarm id natively (UserDefaults) as soon as AlarmKit has it, not at the end and not only in JS. If a booking throws halfway, the next re-booking has to know which alarms are live.&lt;/li&gt;
&lt;li&gt;On every re-booking, cancel any alarm AlarmKit holds that isn't in your list. An id lost from an older build or a crash mid-booking would otherwise ring forever.&lt;/li&gt;
&lt;li&gt;Book a few days ahead and re-book on every app open and in background refresh. Prayer times move every day, and one Fajr is 31 system alarms.&lt;/li&gt;
&lt;li&gt;Spread the backups over the whole time the app still asks for the proof. My first version rang every 30 seconds for 20 rings. That stopped after 10 minutes while the app still wanted the proof, so someone who tapped "I'm up" on a locked phone and fell back asleep heard nothing more.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "I'm up" has to stop the ring itself
&lt;/h2&gt;

&lt;p&gt;The second button is a &lt;code&gt;.custom&lt;/code&gt; button that opens the app. A custom button doesn't stop the alarm by itself. When I left it alerting, the ring went quiet behind the app, held back the backups, and when the phone was locked again they all came at once. The fix is to stop that one ring in the intent before the app opens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;FajrWakeIntent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;LiveActivityIntent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;LocalizedStringResource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Wake up for Fajr"&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;openAppWhenRun&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

  &lt;span class="kd"&gt;@Parameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Alarm ID"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;alarmID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

  &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;perform&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;throws&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;some&lt;/span&gt; &lt;span class="kt"&gt;IntentResult&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;UUID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;uuidString&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;alarmID&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kt"&gt;AlarmManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kt"&gt;NotificationCenter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fajrWakeOpened&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;object&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;result&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;While the proof screen is open, the app also holds off the next backups for a moment, so a ring doesn't take the microphone in the middle of the du'a. If you put the phone down, the later ones still come.&lt;/p&gt;

&lt;h2&gt;
  
  
  Proof 1: reading the du'a aloud
&lt;/h2&gt;

&lt;p&gt;The default proof is a du'a the Prophet ﷺ said when he woke up:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;الْحَمْدُ لِلَّهِ الَّذِي أَحْيَانَا بَعْدَ مَا أَمَاتَنَا وَإِلَيْهِ النُّشُورُ&lt;/p&gt;

&lt;p&gt;"All praise is for Allah, who gave us life after He caused us to die, and to Him is the return." (Sahih al-Bukhari 6312)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On iOS the app listens with &lt;code&gt;SFSpeechRecognizer&lt;/code&gt; in Arabic, on-device when the phone supports it. On Android it's &lt;code&gt;SpeechRecognizer&lt;/code&gt; with &lt;code&gt;ar-SA&lt;/code&gt;, restarted after each pause with the text kept.&lt;/p&gt;

&lt;p&gt;Recognisers drop the harakat, merge short words and swap letter forms, so comparing the full text never works. Each text has a few key words stored as normalised stems, and you need most of them (4 of 5 for this du'a). Everything the recogniser writes goes through this first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;normalizeArabic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;ً-ٰٟۖ-ۭـ&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// harakat, Quranic marks, tatweel&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;أإآٱ&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ا&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/ى/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ي&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/ة/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ه&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/ؤ/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;و&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/ئ/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ي&lt;/span&gt;&lt;span class="dl"&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;As you read, the words light up on screen, so you can see it's following you.&lt;/p&gt;

&lt;p&gt;In the first ten days about 1 in 4 du'a tries never passed. Most of what's below came from that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My first Android version only measured seconds of voice, so saying anything passed. Android checks the words now too.&lt;/li&gt;
&lt;li&gt;Some voices the recogniser just doesn't get: an accent, a whisper at dawn, no on-device model. One person read for 70 seconds and never got through. Now, if you've read aloud for twice the time the text takes and at least two of its words were heard, it counts.&lt;/li&gt;
&lt;li&gt;With no recogniser at all (no network at dawn and no on-device model), the app falls back to the voice itself and counts the seconds you're speaking. The voice threshold follows the room's own level, because people read softly at dawn so they don't wake the house. A fixed threshold missed them.&lt;/li&gt;
&lt;li&gt;Android's speech service sometimes disconnects mid-read (error 11). That needs a quiet retry, not a failure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Proof 2: a photo of your prayer mat
&lt;/h2&gt;

&lt;p&gt;The other proof is a photo of your prayer mat. There's no setup photo to compare against: a model on the phone judges any photo, and the photo never leaves the phone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;iOS:&lt;/strong&gt; the image encoder of Apple's MobileCLIP S0, converted to Core ML with 8-bit palettized weights. It's not in the app bundle. It downloads (11 MB) the first time someone picks the photo proof and gets compiled on the phone. Offline, I embedded short text prompts with the matching text encoder: "a photo of a prayer rug", "a photo of feet standing on a prayer rug" and a few more on one side, "a photo of a bed", "a photo of a wall", "a photo of a kitchen" and so on on the other. The photo's embedding is compared with all of them using CLIP's logit scale, and the score is the share that goes to the prayer mat prompts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;matScores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mat&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;similarity&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;otherScores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;similarity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matScores&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;otherScores&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// CLIP's logit scale (100), shifted by the top score so exp() can't overflow&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;weight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;score&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;top&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;matWeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;matScores&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;matWeight&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;otherScores&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"mat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;matWeight&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"light"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;brightness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On 30 prayer rug photos and 30 others, the rugs scored 0.75 to 1.00, and beds, kitchens, bathrooms and walls 0.1 or less. The pass mark is 0.45. A patterned carpet can pass, and that's fine: you're up and standing at a rug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android:&lt;/strong&gt; ML Kit's own image labels have no rug or mat, only things like "Textile" and "Pattern". But ImageNet has class 741, "prayer rug, prayer mat". So Android runs EfficientNet-Lite0 (int8, about 5 MB, in the app's assets) through ML Kit's custom image labeler and reads that one class. On 125 photos, prayer mats scored 0.6 to 0.96, and bedrooms, towels and blankets under 0.25. The pass mark there is 0.3.&lt;/p&gt;

&lt;p&gt;Both also return the photo's mean brightness, so a failed photo in a dark room gets "turn on a light" instead of "that's not a prayer mat".&lt;/p&gt;

&lt;h2&gt;
  
  
  Phones without AlarmKit
&lt;/h2&gt;

&lt;p&gt;Android and iPhones before iOS 26 get a run of loud notifications instead: close together at first, then spread out. On Android they play on the alarm stream, so they ring on silent. On older iPhones it's weaker: they're time-sensitive notifications that don't ring with the silent switch on, and iOS only keeps 64 pending notifications per app, shared with the prayer reminders, so there are fewer of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Plan for Stop being pressed. Don't try to fight it.&lt;/li&gt;
&lt;li&gt;Keep the alarm state in native storage. When an alarm opens your app at 5 am, your JS might not be running yet.&lt;/li&gt;
&lt;li&gt;Test on a real phone. The simulator crashed on a custom alarm sound and couldn't find the App Intents.&lt;/li&gt;
&lt;li&gt;Look at what happens on real mornings. The read-twice rule and the room-level threshold both came from failed tries in the first week, not from my own testing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The alarm is part of &lt;a href="https://bettermuslim.net/" rel="noopener noreferrer"&gt;BetterMuslim&lt;/a&gt;, a free app for prayer, Quran, du'as and daily habits, with no ads and no subscription. The alarm is the last step though. What actually gets you up is the night before, and I wrote that part down here: &lt;a href="https://bettermuslim.net/blog/build-consistent-salah-habit/" rel="noopener noreferrer"&gt;How to pray 5 times a day consistently&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're building with AlarmKit and ran into something else, tell me in the comments.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ios</category>
      <category>swift</category>
      <category>android</category>
    </item>
    <item>
      <title>Why your App Store Connect and Google Play Console numbers never match (and never match your analytics)</title>
      <dc:creator>Ahmed Ashour</dc:creator>
      <pubDate>Mon, 26 Oct 2026 00:23:53 +0000</pubDate>
      <link>https://dev.to/ahmedashourdev/why-your-app-store-connect-and-google-play-console-numbers-never-match-and-never-match-your-3895</link>
      <guid>https://dev.to/ahmedashourdev/why-your-app-store-connect-and-google-play-console-numbers-never-match-and-never-match-your-3895</guid>
      <description>&lt;p&gt;I build a few apps on the side, and every morning I opened App Store Connect, Play Console and my analytics, and no two of them agreed.&lt;br&gt;
While building my own dashboard I had to find out why, one number at a time. These are the reasons I found.&lt;/p&gt;

&lt;h2&gt;
  
  
  The store counts downloads, your analytics counts opens
&lt;/h2&gt;

&lt;p&gt;The store counts a download when the app gets installed. Your analytics only sees someone after they open the app with your SDK running. Everyone who downloads and never opens it is in the store number and nowhere else.&lt;/p&gt;

&lt;p&gt;So your analytics "new users" will be lower than store downloads, and that's normal.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Downloads" means different things on each store
&lt;/h2&gt;

&lt;p&gt;On the App Store, first-time downloads and redownloads are separate numbers. Someone who deletes the app and gets it again is a redownload, not a new download. Updates are counted on their own too. Check which one your chart shows before you compare it with anything.&lt;/p&gt;

&lt;p&gt;On Google Play, users and devices are counted apart. A user is a Google account, a device is a phone or tablet. One person who installs on a phone and a tablet is one new user and two new devices. And the installed audience (devices that have the app right now) is a third thing again: it goes down when people uninstall, downloads never do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your analytics counts installs, not people
&lt;/h2&gt;

&lt;p&gt;A reinstall, a second phone, or logging out and back in gives the app a new install id. Count by install id and each of those is a new user.&lt;/p&gt;

&lt;p&gt;When I switched to counting signed-in people by account instead of by install, 8 of 114 people in one of my apps had been counted twice or more.&lt;/p&gt;

&lt;p&gt;Background wake-ups do it too. A silent push that wakes the app to schedule reminders can look like a visit. On one day, 6 of 83 phones my SDK saw had only been woken by a push, nobody opened the app. Now I only count a session where the app was actually open.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test phones look like real users
&lt;/h2&gt;

&lt;p&gt;Google Play runs every build you upload on its own test phones for the pre-launch report. In my data that's a burst right after each upload: OnePlus 8 Pro on Android 11 (API 30), a US IP, random en-XX locales.&lt;/p&gt;

&lt;p&gt;Apple's review opens your new version from a US iPhone, on a version that isn't on the App Store yet. And if your SDK runs in debug builds, simulators send events too. One day, 11 of one app's 28 "new people" were simulators, which was just me testing.&lt;/p&gt;

&lt;p&gt;Across my apps these were about 1 in 10 new people. They also made purchase errors that no real person had, and made the "came back" rate look worse.&lt;/p&gt;

&lt;p&gt;What I filter out now: emulators and simulators, the pre-launch devices, and any phone that only ever ran a version that isn't in the store yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Store data is late
&lt;/h2&gt;

&lt;p&gt;Today never has downloads. Store numbers show up a day or two late, and downloads can take 2 to 5 days to arrive (Play is the slow one).&lt;/p&gt;

&lt;p&gt;So if you put yesterday's store number next to yesterday's analytics, it almost always looks like a drop. Compare days that are a few days old, or compare today with a usual day at the same hour using your own events.&lt;/p&gt;

&lt;h2&gt;
  
  
  Everyone has a different midnight
&lt;/h2&gt;

&lt;p&gt;Each tool ends the day at its own midnight, and it's not always yours.&lt;/p&gt;

&lt;p&gt;My own dashboard had this bug. The Today page started the day at Berlin midnight and every other page at UTC midnight, which is 1 or 2 am here. Same day, different people on two pages. A sale at 00:30 showed up on the day before.&lt;/p&gt;

&lt;p&gt;Daylight saving adds one more: the night the clocks go back, a day has 25 hours. That broke my "same time yesterday" math until I compared by clock time instead of by milliseconds since midnight.&lt;/p&gt;

&lt;p&gt;Before you compare a day across tools, check which timezone each one uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two analytics tools count the same person twice
&lt;/h2&gt;

&lt;p&gt;If an app sends events to two tools (I had Mixpanel and my own SDK side by side for a while), never add their numbers. My per-day table counted a signed-in person twice when both tools saw them. Pick one source for each number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reviews: each store gives you a different half
&lt;/h2&gt;

&lt;p&gt;Google Play's review export includes star-only ratings, but no country. You only get the reviewer's phone language, so "German" means a phone set to German, not a person in Germany.&lt;/p&gt;

&lt;p&gt;The App Store API only returns reviews that have text, with the reviewer's country. Star-only ratings can't be fetched by any tool. So anything that lists your iOS reviews will show fewer than your rating count.&lt;/p&gt;

&lt;h2&gt;
  
  
  App Store usage numbers are a sample
&lt;/h2&gt;

&lt;p&gt;Sessions, active devices and crashes in App Store Connect only come from people who agreed to share analytics with developers. They're a sample, so they'll be lower than what your SDK sees.&lt;/p&gt;

&lt;h2&gt;
  
  
  Money: what they paid vs what you get
&lt;/h2&gt;

&lt;p&gt;Apple's sales reports have both the customer price and your proceeds after Apple's cut. If one tool shows one and another shows the other, they'll never match. Check which one you're looking at.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I do now
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Downloads come from the stores, people come from my own events. I never subtract one from the other.&lt;/li&gt;
&lt;li&gt;People are counted by account, and only when the app is open.&lt;/li&gt;
&lt;li&gt;Test phones are out: pre-launch devices, simulators, unreleased versions.&lt;/li&gt;
&lt;li&gt;Store days only after they've settled. For today I compare with a usual day at the same hour.&lt;/li&gt;
&lt;li&gt;One midnight for everything.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I got tired of this enough that I built &lt;a href="https://apparent.fyi/?ref=devto" rel="noopener noreferrer"&gt;apparent.fyi&lt;/a&gt;, simple analytics that celebrates your app's small wins.&lt;/p&gt;

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