DEV Community

Takuma Yamada
Takuma Yamada

Posted on AI-assisted

Restoring a Reading Session Was More Than Saving a Page Number

Open a PDF, read a few pages, switch to another app, and come back.

That was an everyday part of testing MihirakiPDFViewer, the iPad PDF reader I was building. The page was still there when I returned, so resuming a reading session seemed to work.

But after the app’s process ended, launching it again brought me back to the file picker. The document and reading position were gone.

Returning to a running app and launching it after its process has ended can feel similar to a reader. For the app, they are different conditions.

In Part 3, I described preparing test PDFs with predictable results. This time, I applied the same thinking to reading-session restoration, saved preferences, and importing external PDFs.

The results below come mainly from development logs dated September 8, 2026, using an iPad (A16) Simulator running iOS 26.5. I have not rerun those tests for this article.

Returning to the app did not prove restoration worked

My initial request described a familiar sequence: open a PDF, go to the Home Screen, open several other apps, and return to the reader.

I expected to see the page I had been reading.

The development log recorded two different outcomes before the fix:

Action Recorded result before the fix
Switch to other apps and return Page 15 of 30 remained visible
End the process and relaunch The PDF picker appeared

While the process remained alive, the app could use the document and page information still held in memory. After the process ended, that in-memory state was lost. Continuing from the same place required saving the necessary information and loading it on the next launch.

This also exposed an ambiguity in my request. Opening other apps and returning did not establish that the reader’s process had ended in between.

For the second check, the test explicitly ended the process as a substitute for an interruption caused by memory pressure. It did not reproduce an actual low-memory termination.

“Return to the app” needed a more precise starting condition.

Before the fix: switching away and returning keeps page 15 of 30, while ending the process and relaunching shows the PDF picker.

Figure 1. Before the restoration fix, switching away and returning preserved page 15 of 30, while ending the process and relaunching returned to the PDF picker. This schematic summarizes the recorded Simulator behavior; it does not show a real low-memory termination.

Decide what to restore—and when to stop restoring it

After confirming the failure, I asked AI to modify the app so that a reading session could survive process termination.

The work report described restoring the document, page position, spread settings, and search term. For a regular PDF, it reported successfully restoring page 15 of 30 and the search term.

The page number was only part of the experience. Returning to the same page with different spread settings could still feel like losing my place.

There was another condition to handle: explicitly closing a document.

If I closed a PDF myself, I did not want it to reopen on the next launch. An interrupted session and a document I had deliberately closed represented different intentions.

The app therefore needed to clear the saved reading session when the user explicitly closed the PDF.

Password-protected PDFs added another step. The log reported returning to the previous page after the password was entered again. That result should not be read as restoring a protected document without another password prompt.

The task was becoming more than a list of values to save. I needed rules for when those values should be used—and when they should no longer cause a document to reopen.

A working toggle was not necessarily a saved preference

On the same day, I checked two rendering preferences: high-quality rendering and sharpness.

Both could be enabled in the interface. But after ending the app and relaunching it, both returned to off.

The features worked during the session, but the selected values were not being preserved.

For this issue, a test that reproduced the bug was added and shown to fail before the app was modified. The subsequent work report covered more than relaunching: it also checked closing a document and resetting settings.

I treated these two preferences as app-wide choices. Closing a PDF should leave them unchanged. Resetting settings should return both to their default value of off.

That gave reading-session state and rendering preferences different lifetimes:

  • Relaunch after process termination: Restore the reading session for a document that was not explicitly closed. Preserve the selected high-quality rendering and sharpness values.

  • Explicitly close the PDF: Do not reopen that document on the next launch. Preserve the selected high-quality rendering and sharpness values.

  • Reset settings: Return high-quality rendering and sharpness to off. The effect on reading-session state is outside this article’s checks.

I would now write down these expectations before requesting the implementation. Checking that a toggle changes the current display is only the first step. The next question is what should happen after closing, relaunching, or resetting.

Expected state lifetime: relaunch restores a session and keeps rendering preferences; explicitly closing a PDF prevents it reopening; resetting turns high quality and sharpness off.

Figure 2. Different actions should preserve different parts of the app’s state. Relaunching restores the reading session; explicitly closing a PDF removes it from restoration while keeping the rendering preferences. Here, “rendering preferences” refers only to high-quality rendering and sharpness. The diagram makes no claim about how resetting settings affects reading-session state.

Importing a local PDF did not verify the iCloud workflow

I also wanted to check opening a PDF from outside the app.

Because I used PDFs stored in the cloud, I asked for a test that selected a file in iCloud Drive, opened it in the reader, and checked viewing and search.

The test environment could not complete that exact workflow. The recorded response said that the Simulator control tool could not connect to the required service, preventing the actual Files/iCloud Drive interface from being opened and operated.

Instead, a substitute test used a local PDF. It exercised an entry point equivalent to receiving an external file URL, followed by copying the PDF into app-managed storage, viewing it, and searching it.

That was useful coverage, but it answered a narrower question.

Intended check Evidence available in the referenced records
Select a PDF in iCloud Drive and open it in the reader The actual cloud workflow was not verified
Receive and import an external PDF A substitute test used a local PDF
View and search the imported document Reported as checked within that substitute test

The import implementation included handling access to the external file, coordinating the read, and copying it into storage managed by the app.

Those implementation details mattered. Their presence in the code, however, did not establish that downloading a file from iCloud and opening it through the real interface had succeeded.

I needed to keep the substitute test separate from the end-to-end workflow I originally wanted to verify.

Separate import paths: the actual iCloud Drive workflow was unverified, while a reported substitute test used a local PDF for URL receipt, copying, viewing, and search.

Figure 3. The actual iCloud Drive workflow and the local-PDF substitute test cover different paths. The upper path was not verified in the referenced records. The lower path summarizes the reported substitute test: receive a local PDF through an equivalent external-URL entry point, copy it into app-managed storage, then view and search it. The two paths are intentionally shown separately.

Keep the evidence behind “the tests passed”

The recorded execution of the targeted tests after the fixes ended with exit code 0. The work report also described successful checks for preference persistence, reset behavior, and existing page restoration.

There are limits to that evidence.

When preparing the original article, I did not reopen every test-result file from the temporary locations used during development. The account here relies on execution records and reports retained in the work logs.

Related tests were also present in the code inspected for that article. Their presence is separate evidence from the historical execution results; it does not mean I have run the current tests again.

Part 3 was about understanding what a passing test actually established. The same lesson applied here: everyday observations, the conditions exercised by a test, and the results recorded in a work report each tell us something different.

Persistence includes decisions about user intent

Making it possible to continue reading involved more than writing a page number to storage.

Which document should reopen? Which preferences should remain? What changes when the reader deliberately closes a document?

For a similar feature now, I would start with three steps:

  1. Separate returning, relaunching, closing a document, and resetting settings.
  2. Write down which state should remain or be cleared after each action.
  3. Record the paths actually tested, alongside those still unverified.

AI helped create tests that reproduced the bugs and implement fixes. To judge that work, I still needed to turn my expectations as a reader into concrete actions and observable results.

In your own apps, how do you distinguish an interrupted session from something the user deliberately closed?


Source and code: Adapted and reorganized from my Japanese development article on Qiita. The source code is available on GitHub.

The repository includes later changes. This article is a retrospective based mainly on the September 8, 2026 work logs and code inspected when preparing the original article. It does not report a new test run.

AI disclosure: I used AI assistance to organize and draft this English article and to help create the explanatory diagrams. The development experiences and verification results described here are based on my records.

Top comments (0)