コメント
コメントの投稿
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLTypes</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.999999999999-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
</array>
</dict>
<dict>
<key>CFBundleURLTypes</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.CompanyName.AppName</string>
</array>
</dict>
</array>
namespace AppName.Services
{
//DependencyServiceから利用する
public interface IGoogleSignInService
{
void SignIn();
void SignOut();
void Disconnect();
}
}
using Google.SignIn;
[assembly: Dependency(typeof(GoogleSignInService))]
namespace AppName.iOS.Services
{
public class GoogleSignInService : IGoogleSignInService
{
public static ISignInUIDelegate SignInUIDelegate = new GoogleSignInUIDelegate();
public void SignIn()
{
Google.SignIn.SignIn.SharedInstance.UIDelegate = SignInUIDelegate;
var googleServiceDictionary = NSDictionary.FromFile("GoogleService-Info.plist");
Google.SignIn.SignIn.SharedInstance.ClientID = googleServiceDictionary["CLIENT_ID"].ToString();
Google.SignIn.SignIn.SharedInstance.SignedIn += (sender, e) => {
// ここにログイン後の処理を記述します。
if (e.User != null && e.Error == null)
{
//ここにログイン成功時の処理を記述してください
System.Diagnostics.Debug.WriteLine("Signed in user: {0}", e.User.Profile.Name);
}
};
Google.SignIn.SignIn.SharedInstance.Disconnected += (sender, e) => {
//ここに切断時の処理を記述してください
System.Diagnostics.Debug.WriteLine("Disconnected user");
};
//自動サイレントログイン
//Google.SignIn.SignIn.SharedInstance.SignInUserSilently();
//手動ログイン
Google.SignIn.SignIn.SharedInstance.SignInUser();
}
public void SignOut()
{
Google.SignIn.SignIn.SharedInstance.SignOutUser();
}
public void Disconnect()
{
Google.SignIn.SignIn.SharedInstance.DisconnectUser();
}
}
public class GoogleSignInUIDelegate : SignInUIDelegate
{
public override void WillDispatch(SignIn signIn, NSError error)
{
}
public override void PresentViewController(SignIn signIn, UIViewController viewController)
{
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(viewController, true, null);
}
public override void DismissViewController(SignIn signIn, UIViewController viewController)
{
UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null);
}
}
}
using Google.SignIn;
namespace AppName.iOS
{
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
// For iOS 9 or newer
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
var openUrlOptions = new UIApplicationOpenUrlOptions(options);
return SignIn.SharedInstance.HandleUrl(url, openUrlOptions.SourceApplication, openUrlOptions.Annotation);
}
// For iOS 8 and older
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
return SignIn.SharedInstance.HandleUrl(url, sourceApplication, annotation);
}
}
}
void OnGoogleSignInClick(object sender, EventArgs e)
{
DependencyService.Get<IGoogleSignInService>().SignIn();
DependencyService.Get<IGoogleSignInService>().SignOut();
DependencyService.Get<IGoogleSignInService>().Disconnect();
}
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。