Compile your own Telegram for iOS

Telegram is a very popular multi-platform client open source chat software in the last two years.
Since the client is open source, I’m going to compile it myself and take a look.
There is already some information on how to compile Telegram on the web, but this information is probably not available due to code updates.

pull code

``Git. git clone cd Telegram-iOS/

Telegram-iOS Most of the functionality is provided by submodule, so you need to pull the submodule as well.

git submodule update –init –recursive

After pulling the completion of the project with Xcode to open the project, and found that many submodule is missing.  
The result is to open the submodule file found that many module url point to a relative path....
[submodule "submodules/AsyncDisplayKit"]
	path = submodules/AsyncDisplayKit
url=. /AsyncDisplayKit.git
[submodule "submodules/Display"]
	path = submodules/Display
url=. /Display.git
[submodule "submodules/HockeySDK-iOS"]
	path = submodules/HockeySDK-iOS
url=. /HockeySDK-iOS.git
[submodule "submodules/libtgvoip"]
	path = submodules/libtgvoip
[submodule "submodules/lottie-ios"]
	path = submodules/lottie-ios
url=. /lottie-ios.git
[submodule "submodules/MtProtoKit"]
	path = submodules/MtProtoKit
url=. /MtProtoKit.git
[submodule "submodules/Postbox"]
	path = submodules/Postbox
url=. /Postbox.git
[submodule "submodules/SSignalKit"]
	path = submodules/SSignalKit
url=. /Signals.git
[submodule "submodules/TelegramCore"]
	path = submodules/TelegramCore
url=. /TelegramCore.git
[submodule "submodules/TelegramUI"]
	path = submodules/TelegramUI
url=. /TelegramUI.git
[submodule "submodules/ffmpeg"]
	path = submodules/ffmpeg
url=. /ffmpeg.git
[submodule "submodules/LegacyComponents"]
	path = submodules/LegacyComponents
url=. /legacycomponents.git
[submodule "submodules/webp"]
	path = submodules/webp
url=. /webp.git

Fortunately, all the modules pointing to relative paths are actually under the account.
So, manually modify the url of all the relative paths and pull the submodule again to get all the submodules you need.

Compile and make the necessary changes

It is now possible to open projects using Xcode, although there are still too many bugs to fix.
First, I changed the Bundle ID to the one I need.
The next step is to configure the developer account, and configure all targets to have their own developer account.
There are still a lot of errors after configuration, mainly with the Capabilities.
The main problem with opening Capabilities is that the App groups ID needs to be configured as the ID of your own developer account, and the Telegram project itself has Apple Pay enabled so you need to configure the Merchant ID. After the configuration of all the errors should be gone, and began to compile with aplomb …
The result is an error: Yasm not found.

Well, the search revealed that this is a small problem, and it’s a good idea to install the package directly via brew. ``bash. brew install yasm

Start compiling again, this time with the problem `Use of undeclared identifier 'APP_CONFIG_DATA' `, and find the corresponding solution in the list of project issues:  
Find the corresponding once[commit](, put `Telegram-iOS/ BuildConfig.m' new contents are commented and the three values are replaced with your own AppID from  
In the latest 5.7 source code version, only the following three items need to be changed without commenting.
- (NSData * _Nullable)bundleData {
    return nil;//_bundleData;

- (int32_t)apiId {
    return 123456;//_apiId;

- (NSString * _Nonnull) apiHash {
    return @"aaabbbcccdddeeefff";//_apiHash;

Replace it and compile it again, and it should pass.

Some notes

  • ``Telegram-iOS/Config-Fork.xcconfig` is the target we need to compile, and I’ve also included the Bundle ID and AppID in this file.
  • Note the relationship between the BundleID for Notification and other extensions and the BundleID for Telegram.


Originally thought APNS is no hope, but in Telegram’s console actually saw the function of uploading APNS certificate, after uploading the certificate correctly, APNS can also work normally.
I just need to note that only pem format certificate is accepted in the background.

Unblock groups and channels.

Edit TelegramCore/Network/Api1.swift’s parse_channel function, add content after if Int(_1!) & Int(1 << 17) ! = 0 {_13 = reader.readInt32() } swift`swift parse_channel function, add content after Int(_1!) & Int(1 << 17) ! swift. _1 = _1! & ~(1 « 9) & ~(1 « 18) _9 = nil _12 = nil ```