惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 胖胖安

Xamarin.Android 的 Google 登入 Xamarin.Android 的照相機使用 Xamarin.iOS 照相機功能的使用 (1) :最簡單的做法 Xamarin.iOS 的鍵盤控制 (AutoLayout 與 新的 Keyboard 事件 ) Xamarin.Android 控制鍵盤縮放 Xamarin 環境建置–Xamarin Agent install rvm iOS : TableView MultiSelect 兩個 System.IO.FileInfo 的 Extension Method SQL Server 2008 Resize LDF IIS 7 站點下,ASP.NET 3.5 與 4.0 的並存問題 jQuery AutoComplete Parameters Tips : SQL Server 2008 "saving changes is not permitted." 的解決辦法 - 胖胖安 Section 3 : 程式進入點 Section 2 : 專案結構 Section 1 : 使用 XCode 建立一個新專案 iPhone 開發前的準備工作 IIS 7 上 设定ASP.NET 时应注意事项 DBML 在Beta2與正式版間差異 - 胖胖安 - 博客园
Xamarin.iOS 的 Google 登入
胖胖安 · 2016-04-19 · via 博客园 - 胖胖安

在 Xamarin.iOS 開發中,使用Google 帳號進行登入,十分簡單。
只要引入 Xamarin 為 Google Single-SignIn 開發的 Component 即可。

首先在專案的 Components 目錄下引入「Google Sign-In for iOS」

然後只要幾行code就可以完成Google Sin-In 的工作。
真正的問題在Server端的設置。

首先到 https://developers.google.com/mobile/add 這邊增加 iOS App
給出 App name 和 bundle id
然後再下一個頁面增加 Google Sign-In 的功能。

接下來是要記得產生設定檔案
然後下載 GoogleService-Info.plst 檔案,加入至專案。

然後在專案總管這邊,Build Action 選成 BundleResource 。

在 Info.plist 這邊要做兩件事情
新增 CFBundleURLTypes 讓 Google 可以辨識

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLTypes</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>填入REVERSE_CLIENT_ID,去GoogleService-Info.plist 內找出來</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleURLTypes</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>在Google 開發者網站填的Bundle Id</string>
            </array>
        </dict>
    </array>

做到這邊,關於設定的工作就做好了。

而程式碼分成兩部分。
皆需要引用以下的 namespace

using Google.Core;
using Google.SignIn;
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)

需要加上這段 Code 讀取 ClientID ,這邊需要去 GoogleService-Info.plist 複製 CLIENT_ID 出來。

NSError configureError;
Context.SharedInstance.Configure (out configureError);
if (configureError != null) {
  Console.WriteLine ("Error configuring the Google context: {0}", configureError);
  SignIn.SharedInstance.ClientID = "要去GoogleService-Info.plist 取得 CLIENT_ID";
}
public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
  return SignIn.SharedInstance.HandleUrl (url, sourceApplication, annotation);
}

另外的目標 ViewController 內加入以下的程式碼

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();

    SignIn.SharedInstance.UIDelegate = this;

    SignIn.SharedInstance.SignedIn += (object sender, SignInDelegateEventArgs e) => {

        if (e.User != null && e.Error == null) {
            Debug.WriteLine(e.User.Profile.Name);
        }
    };

    SignIn.SharedInstance.Disconnected += (object sender, SignInDelegateEventArgs e) => {

        if (e.User != null && e.Error == null) {
            Debug.WriteLine(e.User.Profile.Name);
        }

    };

    SignIn.SharedInstance.SignInUserSilently ();

}
SignIn.SharedInstance.SignInUser ();
SignIn.SharedInstance.SignOutUser ();
SignIn.SharedInstance.DisconnectUser ();


分別用於登入,登出和解除予應用程式的授權。

參考資料:Google Sign-In for iOS 的說明。
程式碼位置:https://github.com/FangHuaiAn/Xamarin-iOSTips