📜 ⬆️ ⬇️

The ATP “Prav.ru” application for iOS - development challenges and ways to solve them

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

Development


In the process of implementing the Pravo.ru ATP for iOS, we faced some difficulties. The first was that the PCA is represented by a large database of documents that 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 application resources (including ours) mainly due to cache cleaning. However, documents updated from the web should be stored in the memory of the mobile device. And we have found the optimal solution in which opening such documents comes from cached data, however documents downloaded from the web will be guaranteed to be saved on the device without loss during cache cleaning.

What is the secret? How can I clean the cache and not lose documents? Answer in the backup. The fact is that after each update of documents, they are automatically saved in a zip file (which “compresses” text data up to 10 times). The 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 keep data on the device intact, without cluttering up the disk device.
')
To implement the save to zip, various libz.dylib wrappers were tried. The main disadvantage was working through memory without streaming. They did not suit us because of the large size of the output zip file. ATP dropped due to rapid memory exhaustion. I had to take the ZipArchive library and implement streaming save in it myself. In addition, we added a visualization of the progress of the execution of conservation through the delegation of events. The code can be taken here .

Until last year, the ATP application 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 at the same time remained unchanged, we still use JSON, but switched to another library of its parsing.

All sorts of libraries are compared here . The implementation of the new JSONKit library instead of the old SBJSON was not difficult, because the developers used design patterns. In order to make the program independent of the libraries used, we used the Proxy (Proxy) design pattern. Its purpose is that it encapsulates the logic of data conversion in general from any protocol that is involved in a web service. So it is possible to switch to an economical Protobuf , and almost as painlessly.

Another design pattern that provides ATP scalability is the Compositor. Based on it, we wrote a caching mechanism. Further, by providing one or another heir of 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 repressive storage queue and become invalid after 1 day. However, if the user does not have the opportunity to obtain more recent data (there is no Internet connection), he will safely receive them from an invalid cache. Thus, the developers have made a flexible mechanism that allows changing the concept of caching for the entire application, as well as for individual parts as a whole.

The main 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, using the svaypu on the search result, that part of the document immediately opens, where the search query is found. At the same time the application selects the desired text.

Arbitrage practice


Indicate the rule of law, go to the related documents and tick the authorities of interest and the courts.

Editorial document


Using the application all existing editions at your fingertips. When working with the text of the document, open the list of revisions and select the desired one.

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

Source: https://habr.com/ru/post/150158/


All Articles