Let me recommend other platforms used in Telegram.
English articles read here:
Logging is a recording of app activities. TelegramCore module provides simple
It supports logging into consoles and system files if log flags are enabled. A queue used to record non-main-thread. redactSensitiveData puts sensitive data in the message log or not.
For modules that do not depend on TelegramCore, the project sets up a bridge function in
the registeredLoggingFunctions function in
the Network file.swift. It will affect other modules such as MtProtoKit, Postbox,and TelegramApi.
It is not a framework that supports multi-level logging. There are many modules that simply print out via the NSLog command and print. For example, when opening a url it prints through the printcommand , this does not seem like a good idea.
It is reasonable that Telegram does not want to use a 3rd party library to avoid leakage of user data. I was surprised that there wasn't a module that recorded the history of crashes, even a home-leaf module. First they added Hockey but then removed it by the BDC0bb2 commit. Perhaps engineers relied on appstore reports to test stability.
To support data sharing between main app, app extensions, watch app, data storage application at group container folder, named telegram-data. Some successor components still use document folder. Here's telegram-data's directory tree layout:
Besides direct write reading, the project uses SQLite to store data. 2 sqlite extensions are enabled:
SQLCipher for full data history encryption and
FTS5 for text search. This approach is also used in other applications, for example WeChat and SignalApp.
LMDB – the Btree storage tree that provides objective-C components: like
TGEmbedCoubPlayerView (embedded player by coub.com),
and TGMediaEditingContext is responsible for editing photos and videos during multimedia messaging.
Messaging and VoIP calls are the two main scenarios that need network transport. Reliable connectivity and real-time updates are important characteristics of a messaging app, which is a challenge because the global network environment is quite complex. Some tricks have been created and widely applied in messaging applications: hybrid endpoint discovery, domain fronting … I will try to write more on this topic in other articles.
MTProto – a Telegram core protocol, designed to support multiple transport protocols. The current version of Telegram-iOS only supports TCP transport. The HTTP transport method was removed in 2018. The VoIP –
libtgvoip module supports both UDP and TCP transports.
Telegram-iOS also leverages VoIP notifications from PushKit to receive data over Apple's network. It's another widely used trick that allows the app to package data in the notification load and process in the background without the need for an interactive user. This is necessary for core features, like updating unread messages, retrieving new endpoints if the application cannot connect to the backend, updating the location online, etc.
Since any abuse can cause significant battery drain problems, Apple began requesting CallKit invoke apps after receiving VoIP notifications since the iOS SDK 13. But Telegram-iOS still seems to exist from the new rule because it has received special rights from Apple:
com.apple.developer.pushkit.unrestricted-voip. The same benefit is also found in the SignalApp application.
Besides using the AsyncDisplayKit library to display the interface, Telegram-iOS goes even further when completing UIKit controllers and views. Most components of UIKit can be found in the project:
to UITableViewController) etc. This approach is quite reasonable, when you do not receive consistency in behavior between IOS operating systems.
It's funny that most iOS engineers will eventually learn some trick changes on UIKit. Somehow, the re-implementation of components such as the UINavigationController so that it works is not the same as the prototype. One of my favorite parts is how to make UINavigationController move sideways.
Two Lottie libraries,
lottie-ios,were built to support After Effect animations. rlottie to support animated stickers in their thetgs format. Lottie-ios supports dynamic images from bundled resources. It seems that it is not necessary to use these 2 libraries at once,
lottie-ios can be replaced with
This application does not have unit test.
So we have grasped the main components of the Telegram-iOS application. In the next articles, we will study MTProto Connections. Follow this blog and share it with many people. Thank you for reading.