telegram-crawler/data/core.telegram.org/passport/sdk-ios-mac.html
2021-11-01 17:49:45 +00:00

246 lines
11 KiB
HTML

<!DOCTYPE html>
<html class="">
<head>
<meta charset="utf-8">
<title>iOS &amp; 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 &amp; macOS apps. Check out our GitHub repository…">
<meta property="og:title" content="iOS &amp; macOS SDK">
<meta property="og:image" content="">
<meta property="og:description" content="TGPassportKit helps you easily integrate Telegram Passport requests into your iOS &amp; macOS apps. Check out our GitHub repository…">
<link rel="shortcut icon" href="/favicon.ico?4" type="image/x-icon" />
<link href="/css/bootstrap.min.css?3" rel="stylesheet">
<link href="/css/telegram.css?213" rel="stylesheet" media="screen">
<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 &amp; macOS SDK</a></li></ul></div>
<h1 id="dev_page_title">iOS &amp; macOS SDK</h1>
<div id="dev_page_content"><!-- scroll_nav -->
<p>TGPassportKit helps you easily integrate Telegram Passport requests into your iOS &amp; 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 &gt; Source Code</strong> and adding this snippet:
<em>Replace <code>{bot_id}</code> with your value</em></p>
<pre><code>&lt;key&gt;CFBundleURLTypes&lt;/key&gt;
&lt;array&gt;
&lt;dict&gt;
&lt;key&gt;CFBundleURLSchemes&lt;/key&gt;
&lt;array&gt;
&lt;string&gt;tgbot{bot_id}&lt;/string&gt;
&lt;/array&gt;
&lt;/dict&gt;
&lt;/array&gt;
&lt;key&gt;LSApplicationQueriesSchemes&lt;/key&gt;
&lt;array&gt;
&lt;string&gt;tg&lt;/string&gt;
&lt;/array&gt;</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 &lt;TGPassportKit/TGPAppDelegate.h&gt;
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary&lt;UIApplicationOpenURLOptionsKey, id&gt; *)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 &lt;TGPassportKit/TGPButton.h&gt;
@interface ViewController &lt;TGPButtonDelegate&gt;
@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 &lt;TGPassportKit/TGPRequest.h&gt;
- (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>
<li><a href="//telegram.org/blog">Blog</a></li>
<li><a href="//telegram.org/jobs">Jobs</a></li>
</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>
<li><a href="//telegram.org/dl/android">Android</a></li>
<li><a href="//telegram.org/dl/wp">Windows Phone</a></li>
</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>
<script src="/js/main.js?42"></script>
<script src="/js/jquery.min.js?1"></script>
<script src="/js/bootstrap.min.js"></script>
<script>window.initDevPageNav&&initDevPageNav();
backToTopInit("Go up");
removePreloadInit();
</script>
</body>
</html>