Dark background with blue accents with light reflectionsDark background with blue accents with light reflectionsDark background with blue accents with light reflections
[5] ABTco.us Development Diary for iOS 7

[5] ABTco.us Development Diary for iOS 7

[5] Development diary of ABTco.us for iOS 7

We continue to tell you about the development process of the updated version of the ABTco.us application for iOS 7. The story is personally led by the CEO of Unreal Mojo studio Thank Karpenko, so interesting and informative reading is guaranteed. Today we bring you another entry of this diary.

Day 6

Or rather "sixth episode"

Last time I settled on doing more or less general work with the news table, even rewriting the process of displaying the bubble with the number of comments. The next day, I discovered that I slightly screwed up with the calculation of the width of this very bubble - I put a plus instead of a minus in the formula, as a result, the “wider” the number was, the bubble was already obtained. Corrected.

Next, I connected notifications about changes in the state of objects so that the table is properly updated when, for example, you read an article, or when the number of comments on an article changes.

Because the first two versions of the application worked differently with the server, often creating unnecessary load, and especially because of the annoying limitation of the server architecture, if the application did not start for several days, there was a chance to skip several articles, that they came out at the time that you did not launch it, it was decided to change the methodology for working with the server API.

Previously (in ABTco.us 1. x and 2. x), the application requested the server for a list of the latest published articles with all attributes (title, author, date, number of comments, link to article, link to a picture and a cloud of all sorts of other things). In addition to eating extra traffic for users, it also generated a lot of excess traffic on the server. Therefore, in version 3 of the application, it was decided to do it differently: now it only requests a list of article IDs with a publication date, and then, only if the database does not have the rest of the data for each of the required articles, it asks the server for data for specific required articles. To minimize the load on the server (and we remember that the application is used by tens of thousands of people every day), such requests are also grouped by the application and sent in batches: all requests for obtaining information about the article in the past second are collected in a heap and sent to the server.

Based on these considerations, I wrote a system that would accumulate requests and query the server. Since different application modules can theoretically request different pieces of information about an article, it was also necessary to implement the logic for grouping requests by information type:

After solving these problems in a few hours and testing the work of the newly written code, I moved on to the next task: displaying images for articles.

It was decided to use Path's FastImageCache to store images . The decision was made for many reasons: storing all downloaded pictures on disk as separate .jpg files, as was done in previous versions of the application, is very expensive in terms of performance, as a result, when the user scrolled up and down the list of news, for each cell I had to load the file from disk, unpack it (aka JPEG) and only then draw. Of course, there were a number of optimizations in previous versions, but what the guys from Path offer, I generally liked more.

I will leave out of the brackets the fact that I generally feel very good about Path, as their co-founder Dustin Mierau once started his programming career at my first company, helping develop the MacAmp player.

In about an hour, I integrated the library into the code, at the same time immediately writing code that would cut the resulting image into a circle through UIBezierPath, as in design. Then I connected the code to the network manager, which requests images through the second NSURLSession (with a low execution priority) and everything magically worked: entities of type " - as in the screenshot above in the article about "General Director". I added a code that translates them into regular UTF-8 (using a piece of GoogleToolboxMac).

At the same time, I found out that on the server all “small” pictures for articles are stored in the form of not quite small ones - often under 100 kilobyte and somewhere around 650 pixels wide (whereas the application needs a maximum of 140). The application, of course, after downloading the picture, cuts it into the desired view, but it seems that extra traffic is also not needed. I consulted with the guys who are engaged in the server side for ABTco.us, they will try to reduce such images on the server in the future. The good news is that there will be no need to redesign the application for this ☺

At this point, the work on creating the list of news can be considered more or less completed. For him, it remains to be done:

  1. Search - I will do this later
  2. Sharing in the social network - I will also do this later, after I make a controller for viewing the text of the news, which the same sharing will be needed
  3. Switch on top News - Favorites - Categories. I will do it right after viewing the text of the news
  4. Implement the display of advertising banners.

It's time to implement the next controller that directly shows the news:

As in previous versions, this is essentially a wrapper over UIWebView, since the text of the article comes to us in HTML. The controller differs from a regular browser in a very complex logic of working with the content of the article.

From the old version, I took the code that inserts the text of the article into the HTML template, which is then shown in the web view. Of course, the HTML itself and the styles had to be sharpened to make it look like what the designer drew (in some places, of course, he fantasized something that I can’t do, but I never do without it, so you always need to look for reasonable compromises or ignore mega-ideas ;).

When a user touches an image or link while reading an article, a moderately branched algorithm of checks on what needs to be done is activated:

  • If this is an image, then you need to show it in full screen in a separate controller;
  • If this is a link to a certain web page, then you need to understand whether this is an external link or a link to an article on ABTco.us;
  • If the link is external, then see if it is allowed to open it without asking the user about whether he wants to follow it (there is a set of certain rules that make it clear whether to ask or not to ask);
  • If the link is internal, then see if it is whether this is a link to an article with a “letter” title (for example, https://abtco.us/sluxi/sluxi-evad3rs-prodalis-kitajcam-za-million-dollarov.html - in it such a “letter” part will be “sluxi- evad3rs-prodalis-kitajcam-za-million-dollarov"). Do a search in your own database in search of this tag for articles (suddenly it does not need to be loaded). If nothing was found, then ask the server what identifier belongs to an article with that name, then load the data and show a new controller with this article;
  • If the link is internal, but of the form https://abtco. us/? p=241842, then get the identifier (241842) from the link, then search for it in your own database, if not, then ask the server about it, then download the data and also show the article.

Collected, partially rewrote the code and voila!

After that, I began to implement the logic of following links to the article and found that the server was broken and did not return the necessary data (a common thing for any project that interacts with any server). While the guys there understand, I will do other things, since there is enough work.

< Previous post



Read this article in other languages: