SPS Pravo.ru application for iOS - development difficulties and solutions

In May 2010, we released the first mobile client of the Pravo.ru legal reference system for iOS devices. At that time, this was the first application providing access to regulatory acts and other official documents of the Russian Federation. In December 2010, an application for the iPad . So today, SPS Pravo.ru for iOS is the leader in the number of installations among legal reference systems. sofbix He told the story of the creation of the application, described the problems that he encountered, and ways to solve them.


In the process of implementing ATP "Pravo.ru" for iOS, we encountered some difficulties. The first was that the PCA is represented by a large database of documents, which are difficult to store on the device. It may be that there is not enough space on the device. At the same time, the operating system frees up application resources (including ours) mainly by clearing the cache. However, documents updated from the web must be stored in the memory of the mobile device. And we found the optimal solution in which the opening of such documents comes from the cached data, however, the documents downloaded from the web will be guaranteed to be saved on the device without loss when cleaning the cache.

What is the secret? How can I clean the cache without losing documents? The answer is in backup. The fact is that after each update of documents they are automatically saved to a zip file (which “compresses” text data up to 10 times). Zip is saved, and when the cache is cleared and documents stored locally are needed, the document recovery mechanism will be launched. Such a flexible system allows you to leave data on the device safe, without cluttering the device’s disk.

To implement saving in zip, various libz.dylib wrappers have been tried. The main drawback was working through memory without streaming storage. They did not suit us because of the large size of the output zip file. ATP fell due to the rapid "exhaustion" of memory. I had to take a library ZipArchive and implement streaming saving in it yourself. In addition, we have added visualization of the progress of the save through the delegation of events. The code can be taken here .

Until last year, the SPS app for iOS worked slowly with the network. This was noticeable when opening documents from the server or when downloading updates. We managed to increase the speed several times, while the memory requirements, on the contrary, decreased. The protocol for working with web services has remained unchanged, we still use JSON, but switched to another library for parsing it.

All kinds of libraries are compared here . Introducing the new JSONKit library there was no difficulty because the developers used design patterns. In order to make the program independent of the libraries used, we used the proxy design pattern. Its purpose is that it encapsulates the logic of data transformation in general from any protocol that is involved in a web service. So it’s possible to switch to the economical Protobuf , and it’s almost as painless as possible .

Another design pattern that provides the scalability of ATP is the Compositor. Based on it, we wrote a caching mechanism. Further, by providing this or that heir to the abstract caching class (at the moment we have 8 implementations) to the data provider, we could get this or that effect. For example, documents are sent to the preemptive queue of the store and become invalid after 1 day. However, if the user does not have the opportunity to get more recent data (there is no Internet connection), he will safely receive them from the invalid cache. Thus, the developers made a flexible mechanism that allows changing the concept of caching both for the entire application and for individual parts as a whole.

Key features of the application for today:

Regional legislation

In the search results, you can specify the regions whose documents you are interested in.

Quick navigation

Now, on a swipe on the search result, that part of the document where the search query is encountered immediately opens. In this case, the application selects the search text.

Arbitrage practice

Indicate the rule of law, go to related documents and mark the instances and courts of interest.

Revision of a document

With the application, all existing editions are at your fingertips. When working with the text of a document, open the list of editions and select the one you need.

We continue to support and develop the application, taking into account the wishes and advice of users. We will be happy to answer questions!