2022-05-14 00:37:40 +02:00
<!DOCTYPE html>
< html class = "" >
< head >
< meta charset = "utf-8" >
< title > iOS & macOS SDK< / title >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< meta property = "description" content = "TGPassportKit helps you easily integrate Telegram Passport requests into your iOS & macOS apps. Check out our GitHub repository…" >
< meta property = "og:title" content = "iOS & macOS SDK" >
< meta property = "og:image" content = "" >
< meta property = "og:description" content = "TGPassportKit helps you easily integrate Telegram Passport requests into your iOS & macOS apps. Check out our GitHub repository…" >
< link rel = "icon" type = "image/svg+xml" href = "/img/website_icon.svg?4" >
< link rel = "apple-touch-icon" sizes = "180x180" href = "/img/apple-touch-icon.png" >
< link rel = "icon" type = "image/png" sizes = "32x32" href = "/img/favicon-32x32.png" >
< link rel = "icon" type = "image/png" sizes = "16x16" href = "/img/favicon-16x16.png" >
< link rel = "alternate icon" href = "/img/favicon.ico" type = "image/x-icon" / >
< link href = "/css/bootstrap.min.css?3" rel = "stylesheet" >
2023-03-20 12:08:32 +01:00
< link href = "/css/telegram.css?236" rel = "stylesheet" media = "screen" >
2022-05-14 00:37:40 +02:00
< style >
< / style >
< / head >
< body class = "preload" >
< div class = "dev_page_wrap" >
< div class = "dev_page_head navbar navbar-static-top navbar-tg" >
< div class = "navbar-inner" >
< div class = "container clearfix" >
< ul class = "nav navbar-nav navbar-right hidden-xs" > < li class = "navbar-twitter" > < a href = "https://twitter.com/telegram" target = "_blank" data-track = "Follow/Twitter" onclick = "trackDlClick(this, event)" > < i class = "icon icon-twitter" > < / i > < span > Twitter< / span > < / a > < / li > < / ul >
< ul class = "nav navbar-nav" >
< li > < a href = "//telegram.org/" > Home< / a > < / li >
< li class = "hidden-xs" > < a href = "//telegram.org/faq" > FAQ< / a > < / li >
< li class = "hidden-xs" > < a href = "//telegram.org/apps" > Apps< / a > < / li >
< li class = "" > < a href = "/api" > API< / a > < / li >
< li class = "" > < a href = "/mtproto" > Protocol< / a > < / li >
< li class = "" > < a href = "/schema" > Schema< / a > < / li >
< / ul >
< / div >
< / div >
< / div >
< div class = "container clearfix" >
< div class = "dev_page" >
< div id = "dev_page_content_wrap" class = " " >
< div class = "dev_page_bread_crumbs" > < ul class = "breadcrumb clearfix" > < li > < a href = "/passport" > Telegram Passport< / a > < / li > < i class = "icon icon-breadcrumb-divider" > < / i > < li > < a href = "/passport/sdk-ios-mac" > iOS & macOS SDK< / a > < / li > < / ul > < / div >
< h1 id = "dev_page_title" > iOS & macOS SDK< / h1 >
< div id = "dev_page_content" > <!-- scroll_nav -->
< p > TGPassportKit helps you easily integrate Telegram Passport requests into your iOS & macOS apps. Check out our < a href = "https://github.com/TelegramMessenger/TGPassportKit" > GitHub repository< / a > to see samples using this SDK.< / p >
< h3 > < a class = "anchor" href = "#installation" id = "installation" name = "installation" > < i class = "anchor-icon" > < / i > < / a > Installation< / h3 >
< h4 > < a class = "anchor" href = "#installing-using-cocoapods" id = "installing-using-cocoapods" name = "installing-using-cocoapods" > < i class = "anchor-icon" > < / i > < / a > Installing using Cocoapods< / h4 >
< p > To install TGPassportKit via Cocoapods add the following to your Podfile:< / p >
< pre > < code > target 'MyApp' do
pod 'TGPassportKit'
end< / code > < / pre >
< p > then run < code > pod install< / code > in your project root directory.< / p >
< h4 > < a class = "anchor" href = "#installing-using-carthage" id = "installing-using-carthage" name = "installing-using-carthage" > < i class = "anchor-icon" > < / i > < / a > Installing using Carthage< / h4 >
< p > Add the following line to your Cartfile:< / p >
< pre > < code > github "telegrammessenger/TGPassportKit"< / code > < / pre >
< p > then run < code > carthage update< / code > , and you will get the latest version of TGPassportKit in your Carthage folder.< / p >
< h3 > < a class = "anchor" href = "#project-setup" id = "project-setup" name = "project-setup" > < i class = "anchor-icon" > < / i > < / a > Project Setup< / h3 >
< h4 > < a class = "anchor" href = "#configure-your-infoplist" id = "configure-your-infoplist" name = "configure-your-infoplist" > < i class = "anchor-icon" > < / i > < / a > Configure Your Info.plist< / h4 >
< p > Configure your Info.plist by right-clicking it in Project Navigator, choosing < strong > Open As > Source Code< / strong > and adding this snippet:
< em > Replace < code > {bot_id}< / code > with your value< / em > < / p >
< pre > < code > < key> CFBundleURLTypes< /key>
< array>
< dict>
< key> CFBundleURLSchemes< /key>
< array>
< string> tgbot{bot_id}< /string>
< /array>
< /dict>
< /array>
< key> LSApplicationQueriesSchemes< /key>
< array>
< string> tg< /string>
< /array> < / code > < / pre >
< h4 > < a class = "anchor" href = "#connect-appdelegate-methods" id = "connect-appdelegate-methods" name = "connect-appdelegate-methods" > < i class = "anchor-icon" > < / i > < / a > Connect AppDelegate methods< / h4 >
< p > Add this code to your < code > UIApplicationDelegate< / code > implementation< / p >
< pre > < code > #import < TGPassportKit/TGPAppDelegate.h>
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary< UIApplicationOpenURLOptionsKey, id> *)options {
BOOL handledByPassportKit = [[TGPAppDelegate sharedDelegate] application:application
openURL:url
options:options];
return YES;
}< / code > < / pre >
< p > If you support iOS 9 and below, also add this method:< / p >
< pre > < code > - (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(nullable NSString *)sourceApplication
annotation:(id)annotation {
BOOL handledByPassportKit = [[TGPAppDelegate sharedDelegate] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
return YES;
}< / code > < / pre >
< h3 > < a class = "anchor" href = "#usage" id = "usage" name = "usage" > < i class = "anchor-icon" > < / i > < / a > Usage< / h3 >
< h4 > < a class = "anchor" href = "#add-telegram-passport-button" id = "add-telegram-passport-button" name = "add-telegram-passport-button" > < i class = "anchor-icon" > < / i > < / a > Add Telegram Passport Button< / h4 >
< p > To add the Telegram Passport button, add the following code to your view controller:
< em > Replace < code > {bot_id}< / code > , < code > {bot_public_key}< / code > and < code > {request_nonce}< / code > with your values< / em > < / p >
< pre > < code > #import < TGPassportKit/TGPButton.h>
@interface ViewController < TGPButtonDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
TGPButton *button = [[TGPButton alloc] init];
button.botConfig = [[TGPBotConfig alloc] initWithBotId:{bot_id}
publicKey:@"{bot_public_key}"];
button.scope = [[TGPScope alloc] initWithJSONString:@"{\"data\":[\"id_document\",\"address_document\",\"phone_number\"],\"v\":1}"];
// You can also construct a scope using provided data type classes like this:
// button.scope = [[TGPScope alloc] initWithTypes:@[[[TGPPersonalDetails alloc] init], [[TGPIdentityDocument alloc] initWithType:TGPIdentityDocumentTypePassport selfie:true translation:true]]];
button.nonce = @"{request_nonce}";
button.delegate = self;
[self.view addSubview:button];
}
- (void)passportButton:(TGPButton *)passportButton
didCompleteWithResult:(TGPRequestResult)result
error:(NSError *)error {
switch (result) {
case TGPRequestResultSucceed:
NSLog(@"Succeed");
break;
case TGPRequestResultCancelled:
NSLog(@"Cancelled");
break;
default:
NSLog(@"Failed");
break;
}
}
@end< / code > < / pre >
< h4 > < a class = "anchor" href = "#or-implement-your-own-behavior" id = "or-implement-your-own-behavior" name = "or-implement-your-own-behavior" > < i class = "anchor-icon" > < / i > < / a > ...or Implement Your Own Behavior< / h4 >
< p > If you want to design a custom UI and behavior, you can invoke a Passport request like this:
< em > Replace < code > {bot_id}< / code > , < code > {bot_public_key}< / code > and < code > {request_nonce}< / code > with your values< / em > < / p >
< pre > < code > #import < TGPassportKit/TGPRequest.h>
- (void)performPassportRequest
{
TGPBotConfig *botConfig = [[TGPBotConfig alloc] initWithBotId:{bot_id}
publicKey:@"{bot_public_key}"];
TGPRequest *request = [[TGPRequest alloc] initWithBotConfig:botConfig];
[request performWithScope:[[TGPScope alloc] initWithJSONString:@"{\"data\":[\"id_document\",\"phone_number\"],\"v\":1}"]
payload:@"{request_nonce}"
completionHandler:^(TGPRequestResult result, NSError * _Nullable error) {
switch (result) {
case TGPRequestResultSucceed:
NSLog(@"Succeed");
break;
case TGPRequestResultCancelled:
NSLog(@"Cancelled");
break;
default:
NSLog(@"Failed");
break;
}
}];
}< / code > < / pre > < / div >
< / div >
< / div >
< / div >
< div class = "footer_wrap" >
< div class = "footer_columns_wrap footer_desktop" >
< div class = "footer_column footer_column_telegram" >
< h5 > Telegram< / h5 >
< div class = "footer_telegram_description" > < / div >
Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed.
< / div >
< div class = "footer_column" >
< h5 > < a href = "//telegram.org/faq" > About< / a > < / h5 >
< ul >
< li > < a href = "//telegram.org/faq" > FAQ< / a > < / li >
2022-09-09 12:10:24 +02:00
< li > < a href = "//telegram.org/privacy" > Privacy< / a > < / li >
2022-09-09 23:58:59 +02:00
< li > < a href = "//telegram.org/press" > Press< / a > < / li >
2022-05-14 00:37:40 +02:00
< / ul >
< / div >
< div class = "footer_column" >
< h5 > < a href = "//telegram.org/apps#mobile-apps" > Mobile Apps< / a > < / h5 >
< ul >
< li > < a href = "//telegram.org/dl/ios" > iPhone/iPad< / a > < / li >
2022-09-09 23:58:59 +02:00
< li > < a href = "//telegram.org/android" > Android< / a > < / li >
< li > < a href = "//telegram.org/dl/web" > Mobile Web< / a > < / li >
2022-05-14 00:37:40 +02:00
< / ul >
< / div >
< div class = "footer_column" >
< h5 > < a href = "//telegram.org/apps#desktop-apps" > Desktop Apps< / a > < / h5 >
< ul >
< li > < a href = "//desktop.telegram.org/" > PC/Mac/Linux< / a > < / li >
< li > < a href = "//macos.telegram.org/" > macOS< / a > < / li >
< li > < a href = "//telegram.org/dl/web" > Web-browser< / a > < / li >
< / ul >
< / div >
< div class = "footer_column footer_column_platform" >
< h5 > < a href = "/" > Platform< / a > < / h5 >
< ul >
< li > < a href = "/api" > API< / a > < / li >
< li > < a href = "//translations.telegram.org/" > Translations< / a > < / li >
< li > < a href = "//instantview.telegram.org/" > Instant View< / a > < / li >
< / ul >
< / div >
< / div >
< div class = "footer_columns_wrap footer_mobile" >
< div class = "footer_column" >
< h5 > < a href = "//telegram.org/faq" > About< / a > < / h5 >
< / div >
< div class = "footer_column" >
< h5 > < a href = "//telegram.org/blog" > Blog< / a > < / h5 >
< / div >
< div class = "footer_column" >
< h5 > < a href = "//telegram.org/apps" > Apps< / a > < / h5 >
< / div >
< div class = "footer_column" >
< h5 > < a href = "/" > Platform< / a > < / h5 >
< / div >
< div class = "footer_column" >
< h5 > < a href = "https://twitter.com/telegram" target = "_blank" data-track = "Follow/Twitter" onclick = "trackDlClick(this, event)" > Twitter< / a > < / h5 >
< / div >
< / div >
< / div >
< / div >
2022-12-10 23:50:15 +01:00
< script src = "/js/main.js?47" > < / script >
2022-05-14 00:37:40 +02:00
< script src = "/js/jquery.min.js?1" > < / script >
< script src = "/js/bootstrap.min.js?1" > < / script >
< script > w i n d o w . i n i t D e v P a g e N a v & & i n i t D e v P a g e N a v ( ) ;
backToTopInit("Go up");
removePreloadInit();
< / script >
< / body >
< / html >