The story of one "developer" or how a newcomer to write an application for iOS





So, May 2018. 7 attempts were made in 7 years to start programming something for iOS. And every time the same thing: Objective-C is something scary and incomprehensible, then there is no idea. And then Hello World, once a year, in general, things did not go ...



This time, a new Xcode and a new language for me Swift ... And a new idea, I want to push notifications for my Zabbix server. there is no official stock, and there were no customers at that time ...



Before this, the bot sent a pushgram to the push, but it began to junk and Roskomnadzor arrived in time ... The blocking of the cart does not play a special role, because there is Mikrotik and it was immediately “fixed”.



It was decided to write a Zabbix notifier, which then will be not only for notifications.



As it turned out, just throwing notifications will not work. You need to write an application, install it, take a token from it, raise your push notification server ...



Programming experience was only in PHP. Swift is different, but it didn’t look as intimidating as Objective-C at the time. And Xcode itself is good as an IDE that converts code from old to new, makes hints.



First of all, training videos, learning the Zabbix API itself. But then, one article after another, how NSURLSession works, what frameworks exist.



The first version was only able to log in to the Zabbix server and give triggers and hosts. Then added views of graphs, values, etc.



I will dwell on some points that I encountered when writing the application.



Frameworks



The frameworks did not enter. They are “cool”, comfortable, but then I don’t want to repair the project due to the fact that something has changed. And this has already happened. For myself, I decided not to use them, and it is better to invent my bike to understand how everything works. For JSON requests, there is Alamofire, but I use the built-in NSURLSession because it’s enough for everything.



Tests



More than a year has passed by then, when I decided to add tests :)

I thought that this fascinating thing would save the world ... But ... I wrote several different tests, poked it here ... And laziness came. I don’t see so far tasks in such a small project to devote so much time to tests ... And this is only time to code tests, not to mention UI tests.



image

Encryption



There were several points to the encryption.



Apple by their manuals wants all requests to be encrypted. And it is right. But as practice has shown, not everyone wanted to do https for their Zabbix. In the beginning, I didn’t have the (App Transport Security Settings) option allowing pure http traffic, for which I was crucified in reviews in the AppStore) Then I turned it on not without adventures because Xcode did not perceive my line until I just recreated the entire Info.plist file.



Also, Apple wants to know everything about your application, the usual https traffic does not fall under it. But if you want to encrypt something "in a tricky way," please report to the US authorities.



image



When communicating with one of the users of the application, there was a request for encryption of PUSH messages End-to-End. The message must be encrypted on the Zabbix server, and decrypted only on the phone. For such a thing, Apple has “mutable” notifications. Those. if “mutable-content” has arrived, then in the push you need to change something according to what you write. I had it decrypting the message.



Apple policy here is not against using standard types of encryption. Do you want something of your own, as I wrote above, give me a piece of paper and can show me the key? ...



I used the built-in CommonCrypto lib, so this is considered the standard type of encryption. I had to mess with the code, because most examples are either very outdated, or Xcode shouted that it wasn’t safe, had nothing to work with bytes and data directly, or had fun with IV OpenSSL-a, the offset wasn’t right, then something else wasn’t right. As a result, it was possible to make non-swearing code, and working correctly with OpenSSL when encrypting messages.



Short circuits



And the most exciting topic for me ... I could not write asynchronous code .... So far, at least I haven’t much understood how these closures work.



image



By default, NSURLSession is just asynchronous and I couldn’t understand how to work with it later ... I used DispatchSemaphore to make the code synchronous ... Naturally there were a lot of complaints from users that it crashes and crashes ...



Then all the same, it dawned on me what and how it worked in the circuit, what timeout in NSURLSession, and what’s what. The code was completely replaced by normal, error handlers were added. And life has become better, life has become more fun.



Layout







Yes, I have everything in one Storyboard. I know that this is not very, but so far there are few screens. Maybe I'll put it in xibs later.



iOS 13 has brought changes to screen displays. Previously, all new screens were shown as PUSH i.e. in full screen. Now this screen can be pulled down and it will close.



In general, a bug occurred if you click LogOut and you can simply collapse the login form back. This only happens if the last Xcode is assembled 11. It is edited simply by setting the view option to display only in fullscreen.



Also in iOS 13 SwiftUI appeared, but if you redo the application now, it means forgetting about those who use the application on old devices with old firmware ...



AppStore Layout



Although I wrote the application for myself, then I decided to post it in the AppStore. It's all just pay $ 100 a year and lay it out. The truth is still checking the application, explain why this application, etc.



Because an application for Zabbix, on the logo I wanted to use something that says about Zabbix. But it was not there. I wrote a letter to Zabbix asking whether it is possible to use the outlines of the letter Z ... But no. Therefore, I painted my icon, a slanting curve, but mine)



Finance



The application is almost 2 years old. Spent $ 200 just to have the application in the AppStore. Apart from development and push server.



image

The application has an advertisement from Google ... which brought ... ... $ 5

Disabling advertising brought $ 88 ... But the withdrawal threshold is from $ 150.

Then I will delete ads in general as soon as I reach the withdrawal threshold.



Push server



Yes, yes, it all started for him ... Push notifications are in demand. Once done so that you can encrypt pushy, many switched to encrypted.



There are 2 servers, Moscow and the Netherlands at 2 rubles / day. DNS balancing, Nginx c Let's Encrypt, PHP script for receiving and sending.



Initially, there was a free server on Amazon (15 gig of traffic ...), but as its time began to come, I bought a VPS-ku to move there. And I found the moment that DDOS was going to the hosting provider and vps was not available for 12 hours ... 2 rubles of which I want more. Well, I was still on Amazon and it has not yet affected me. Therefore, then another one was taken for 2 rubles per day, but in a different location. At least some fault tolerance and 15 gigabyte traffic ... The main concerns for Amazon traffic, micro ddos, and you got the money.



I wanted to use Cloudflare as a balancer, but they want the delegation of the entire domain to them, and not under the domain.



Some statistics



Almost 6 thousand downloads. And Brazil is in the top ... who would have thought)



image



findings






All Articles