⬆️ ⬇️

Development under Sailfish OS in the eyes of an iOS developer

Hi, Habr!



The other day, a charming smartphone, color # F9403E, got into the e-Legion office. By identifying marks, it was possible to install its model - Jolla C and OS - Sailfish OS. The manufacturer's site provided us with data on the characteristics of the device and provided information on where to start development.





')

Under the cat you will learn how the process of creating, debugging and installing a mobile application for Sailfish OS.



The characteristics for the smartphone 2016 are not outstanding, but the point is not only in hardware, but also in how software is implemented.







For the OS, Android application support is claimed, but why engage in porting if you can write a “masterpiece” using native development tools.



Spin-Off: who needs it and why



In India and China, large corporations are collaborating with Jolla, the developer of Sailfish OS, to create an alternative OS that will avoid the security and licensing problems that Android has. Also, attention is focused on the new UX / UI as an opportunity to attract customers who use other platforms. In Russia, it was decided to undertake development under Sailfish with an emphasis on the public sector and government needs. You can read this information in other articles on Habré , the Jolla website or on the OMP website



Development environment



When I started developing for iOS, I had to face some difficulties. Having a device running Mac OS X is a must for Xcode. I did not have it. There were two options: hakintosh or virtual machine.

Now macOS is my main operating system, so I was pleasantly surprised by the presence of the Jolla SDK tested on Mac OS X. A flash drive with the Windows installer remained dusty in the table.



Also declared support for other platforms:





And again a link to the official website:

  1. Install VirtualBox (needed to run the emulator)
  2. Download Sailfish SDK
  3. Select components to install
  4. Agree with licensing agreements
  5. ...
  6. PROFIT !!!




The process is very simple, no “dancing with a tambourine” was needed. The installer independently configures communication with the virtual machine and activates the necessary components for debugging the application.



Qt Creator is used as the development environment.







IDE is not as functional as XCode out of the box, but it crashes less often and the syntax highlighting does not fall off :)







Code and language



For UI development, QML - Qt Meta Language is used. For writing logic, you can use C ++ or Python, if you have more experience with these languages.

I chose QML, since for the implementation of a simple application its capabilities are quite enough. QML is a declarative programming language with the help of which visual elements and their interaction are described. The syntax is similar to JSON, the code is read and perceived very easily.



Qt Quick is used to implement base types and elements. You get:



By analogy with iOS and Android, I was looking for this information on the manufacturer’s website. As it turned out, the Qt site is better suited for this purpose. doc.qt.io It contains more documentation and more interesting code examples.

Jolla offers developers to use their own QML module “Sailfish Silica”. The module is designed to create elements with Sailfish styling. The implementation of these components can be found in the pre-installed Components application, and the documentation is distributed as part of the SDK or on the Jolla website .







It also serves to design the application in colors that correspond to the main theme chosen for the smartphone.



Label { text: "Hello habrahabr!" color: Theme.highlightColor x: Theme.horizontalPageMargin width: parent.width - x*2 font.pixelSize: Theme.fontSizeSmall wrapMode: Text.Wrap } 




The concept is somewhat similar to using UIAppearance from iOS, only the settings are not limited to the application.



Creating an interface from standard elements is sometimes even easier than in iOS. Create a button, specify the position and offset relative to other elements. Is done. Perhaps, with the same ease, I managed to work with the interface only since iOS 9, when the NSLayoutAnchor class was added.



Unfortunately, not everything is so good with customization - in some cases you will have to create an element yourself. Also, complaints were caused by the implementation of SilicaWebView , which was never used in the application; the component constantly fell when trying to display information. Instead, I used standard WebView , which is part of QtWebKit .







There were other problems with the web. I launched the application the day after the development began and instead of the news list I saw a blank screen. It took several hours to find a solution to the problem. As it turned out, the application and the browser built into the OS stopped loading HTTPS data. My conscience tormented me for a couple of minutes, after which HTTPS turned into HTTP.



 function requestUrl(source) { var url = "http://newsapi.org/v1/articles?" url += "source=" + source url += "&apiKey=" + apiKey return url } if (status === XMLHttpRequest.DONE) { var objectArray = JSON.parse(req.responseText); if (objectArray.errors !== undefined) { console.log("Error fetching tweets: " + objectArray.errors[0].message) } else { for (var key in objectArray.statuses) { var jsonObject = objectArray.statuses[key]; news.append(jsonObject); } } if (wasLoading == true) { newsObject.isLoaded() } } 




As for the other modules of the application, their implementation did not cause any particular difficulties. We take a proven MVC pattern, add a bit of binding, a pinch of delegation, sprinkle abundantly with animation, mix ... We get at the exit a news application written in a couple of nights in an attempt to try to develop a new platform.



Emulator and real smartphone



As I wrote earlier, the process of launching the application almost did not cause problems. Before installing the SDK, we place a supported version of VirtualBox on the computer, and the installer takes care of the rest.

Next, select the platform to run, click the Start button and run the application.







The emulator does not cause any complaints: everything is stable and fast. At one time, I had a chance to work with one of the first versions of Android emulators, the 5-minute launch of which caused pain and panic attacks. Yes, now things are much better for him, but the sediment remains.

Small problems, however, arose when you run the application multiple times. Older application instances are not terminated, with the result that you have 5-9 simultaneously running instances of the program. After reaching a certain maximum number, the new version does not start, it is necessary to complete the old instances manually.







Running the debug on the device took a little longer. Without studying the documentation, the process was intuitive. After wandering through the settings and clicking on all the appropriate buttons, I discovered the ability to run the application on a device with the specified IP address. I connected the phone to the WiFi network, entered the address and clicked on Start again. Two minutes of waiting, and my program started on Jolla C. Apple heard our prayers and a bunch of Xcode 9 + High Sierra + iOS 11 allow us to work the same miracles.



Impressions



I will not talk about the prospects of this platform in Russia, there are enough articles on this topic, and I don’t want to start another holivar.



As a user, I liked the responsiveness of the device, the ability to interact with the application directly from the main screen, changing the design of all applications after changing the main theme and an intuitive interface.







From the point of view of the developer, there are also many positive impressions left.

The entry threshold is quite low, for a couple of days we managed to create a simple but functional application. At the same time, it is possible to use C ++ for more resource-intensive and complex tasks, only stingy documentation on the manufacturer’s website is depressing.

The interface and UI-elements are easily implemented, only there is a lack of guidance and vision from the Jolla side. Instead of a guideline on the site, I found 1 page dedicated to UX, the main idea of ​​which is expressed in three words: “Simply Beatiful, Logical, Magical”. But what a expanse for designers! You can implement the most daring ideas.



I would be glad to meet Sailfish developers and your feedback on this article!

Have a nice day and good code!



UPD: Thanks to @kirikch for the informative comment with corrections and additions.

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



All Articles