|
17 | 17 | #import "MainViewController.h"
|
18 | 18 |
|
19 | 19 | #import <objc/runtime.h>
|
| 20 | +#import <GameKit/GameKit.h> |
20 | 21 |
|
21 | 22 | #import <FirebaseCore/FIRApp.h>
|
22 | 23 | #import <FirebaseCore/FIRAppInternal.h>
|
|
25 | 26 | #import "AppManager.h"
|
26 | 27 | #import "AuthCredentials.h"
|
27 | 28 | #import "FIRAdditionalUserInfo.h"
|
| 29 | +#import "FIRGameCenterAuthProvider.h" |
28 | 30 | #import "FIROAuthProvider.h"
|
29 | 31 | #import "FIRPhoneAuthCredential.h"
|
30 | 32 | #import "FIRPhoneAuthProvider.h"
|
|
589 | 591 | static NSString *const kPhoneNumberSignInReCaptchaTitle = @"Sign in With Phone Number";
|
590 | 592 |
|
591 | 593 | /** @var kVerifyIOSClientTitle
|
592 |
| - @brief The title for button to verify iOS client. |
| 594 | + @brief The title for button to verify iOS client. |
593 | 595 | */
|
594 | 596 | static NSString *const kVerifyIOSClientTitle = @"Verify iOS client";
|
595 | 597 |
|
596 |
| -/** @var kIsNewUserToggleTitle |
| 598 | +/** @var kGameCenterAuthSectionTitle |
| 599 | + @brief The title for the section of Game Center |
| 600 | + */ |
| 601 | +static NSString *const kGameCenterAuthSectionTitle = @"Game Center"; |
| 602 | + |
| 603 | +/** @var kLogInWithSystemGameCenterTitle |
| 604 | + @brief The title for the button to log into the Game Center account |
| 605 | + */ |
| 606 | +static NSString *const kLogInWithSystemGameCenterTitle = @"Log In System Game Center"; |
| 607 | + |
| 608 | +/** @var kSignInWithGameCenterTitle |
| 609 | + @brief The title for the button to sign in with Game Center |
| 610 | + */ |
| 611 | +static NSString *const kSignInWithGameCenterTitle = @"Sign in Game Center"; |
| 612 | + |
| 613 | +/** @var kLinkWithGameCenterTitle |
| 614 | + @brief The title for the button to link with Game Center |
| 615 | + */ |
| 616 | +static NSString *const kLinkWithGameCenterTitle = @"Link Game Center"; |
| 617 | + |
| 618 | +/** @var kUnlinkWithGameCenterTitle |
| 619 | + @brief The title for the button to unlink with Game Center |
| 620 | + */ |
| 621 | +static NSString *const kUnlinkWithGameCenterTitle = @"Unlink Game Center"; |
| 622 | + |
| 623 | +/** @var kReauthenticateWithGameCenterTitle |
| 624 | + @brief The title for the button to reauthenticate with Game Center |
| 625 | + */ |
| 626 | +static NSString *const kReauthenticateWithGameCenterTitle = @"Reauthenticate Game Center"; |
| 627 | + |
| 628 | +/** @var kNewOrExistingUserToggleTitle |
597 | 629 | @brief The title for button to enable new or existing user toggle.
|
598 | 630 | */
|
599 | 631 | static NSString *const kNewOrExistingUserToggleTitle = @"New or Existing User Toggle";
|
@@ -707,6 +739,8 @@ - (id)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundl
|
707 | 739 | }
|
708 | 740 |
|
709 | 741 | - (void)viewDidLoad {
|
| 742 | + [super viewDidLoad]; |
| 743 | + |
710 | 744 | // Give us a circle for the image view:
|
711 | 745 | _userInfoTableViewCell.userInfoProfileURLImageView.layer.cornerRadius =
|
712 | 746 | _userInfoTableViewCell.userInfoProfileURLImageView.frame.size.width / 2.0f;
|
@@ -745,6 +779,20 @@ - (void)updateTable {
|
745 | 779 | _isNewUserToggleOn = !_isNewUserToggleOn;
|
746 | 780 | [self updateTable]; }],
|
747 | 781 | ]],
|
| 782 | + [StaticContentTableViewSection sectionWithTitle:kGameCenterAuthSectionTitle cells:@[ |
| 783 | + [StaticContentTableViewCell cellWithTitle:kLogInWithSystemGameCenterTitle |
| 784 | + action:^{ [weakSelf logInWithSystemGameCenter]; }], |
| 785 | + [StaticContentTableViewCell cellWithTitle:kSignInWithGameCenterTitle |
| 786 | + action:^{ [weakSelf signInWithGameCenter]; }], |
| 787 | + [StaticContentTableViewCell cellWithTitle:kLinkWithGameCenterTitle |
| 788 | + action:^{ [weakSelf linkWithGameCenter]; }], |
| 789 | + [StaticContentTableViewCell cellWithTitle:kUnlinkWithGameCenterTitle |
| 790 | + action:^{ |
| 791 | + [weakSelf unlinkFromProvider:FIRGameCenterAuthProviderID completion:nil]; |
| 792 | + }], |
| 793 | + [StaticContentTableViewCell cellWithTitle:kReauthenticateWithGameCenterTitle |
| 794 | + action:^{ [weakSelf reauthenticateWithGameCenter]; }], |
| 795 | + ]], |
748 | 796 | [StaticContentTableViewSection sectionWithTitle:kPhoneAuthSectionTitle cells:@[
|
749 | 797 | [StaticContentTableViewCell cellWithTitle:kPhoneNumberSignInReCaptchaTitle
|
750 | 798 | action:^{ [weakSelf signInWithPhoneNumberWithPrompt]; }],
|
@@ -1726,6 +1774,83 @@ - (void)signInFacebookAndRetrieveData {
|
1726 | 1774 | [self signinWithProvider:[AuthProviders facebook] retrieveData:YES];
|
1727 | 1775 | }
|
1728 | 1776 |
|
| 1777 | +- (void)logInWithSystemGameCenter { |
| 1778 | + GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; |
| 1779 | + localPlayer.authenticateHandler = ^(UIViewController * _Nullable viewController, |
| 1780 | + NSError * _Nullable error) { |
| 1781 | + if (error) { |
| 1782 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Game Center Error" error:error]; |
| 1783 | + } else if (viewController != nil) { |
| 1784 | + [self presentViewController:viewController animated:YES completion:nil]; |
| 1785 | + } |
| 1786 | + }; |
| 1787 | +} |
| 1788 | + |
| 1789 | +- (void)signInWithGameCenter { |
| 1790 | + [FIRGameCenterAuthProvider getCredentialWithCompletion: |
| 1791 | + ^(FIRAuthCredential * _Nullable credential, NSError * _Nullable error) { |
| 1792 | + if (error) { |
| 1793 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Game Center Error" error:error]; |
| 1794 | + } else { |
| 1795 | + [[AppManager auth] signInAndRetrieveDataWithCredential:credential |
| 1796 | + completion:^(FIRAuthDataResult * _Nullable result, |
| 1797 | + NSError * _Nullable error) { |
| 1798 | + [self hideSpinner:^{ |
| 1799 | + if (error) { |
| 1800 | + [self logFailure:@"Sign in with Game Center failed" error:error]; |
| 1801 | + } else { |
| 1802 | + [self logSuccess:@"Sign in with Game Center succeeded."]; |
| 1803 | + } |
| 1804 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Sign In Error" error:error]; |
| 1805 | + }]; |
| 1806 | + }]; |
| 1807 | + } |
| 1808 | + }]; |
| 1809 | +} |
| 1810 | + |
| 1811 | +- (void)linkWithGameCenter { |
| 1812 | + [FIRGameCenterAuthProvider getCredentialWithCompletion: |
| 1813 | + ^(FIRAuthCredential * _Nullable credential, NSError * _Nullable error) { |
| 1814 | + if (error) { |
| 1815 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Game Center Error" error:error]; |
| 1816 | + } else { |
| 1817 | + [[self user] linkAndRetrieveDataWithCredential:credential |
| 1818 | + completion:^(FIRAuthDataResult * _Nullable result, |
| 1819 | + NSError * _Nullable error) { |
| 1820 | + [self hideSpinner:^{ |
| 1821 | + if (error) { |
| 1822 | + [self logFailure:@"Link with Game Center failed" error:error]; |
| 1823 | + } else { |
| 1824 | + [self logSuccess:@"Link with Game Center succeeded."]; |
| 1825 | + } |
| 1826 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Link Error" error:error]; |
| 1827 | + }]; |
| 1828 | + }]; |
| 1829 | + } |
| 1830 | + }]; |
| 1831 | +} |
| 1832 | + |
| 1833 | +- (void)reauthenticateWithGameCenter { |
| 1834 | + [FIRGameCenterAuthProvider getCredentialWithCompletion: |
| 1835 | + ^(FIRAuthCredential * _Nullable credential, NSError * _Nullable error) { |
| 1836 | + if (error) { |
| 1837 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Game Center Error" error:error]; |
| 1838 | + } else { |
| 1839 | + [[self user] reauthenticateAndRetrieveDataWithCredential:credential |
| 1840 | + completion:^(FIRAuthDataResult * _Nullable result, |
| 1841 | + NSError * _Nullable error) { |
| 1842 | + [self hideSpinner:^{ |
| 1843 | + if (error) { |
| 1844 | + [self logFailure:@"Reauthenticate with Game Center failed" error:error]; |
| 1845 | + } else { |
| 1846 | + [self logSuccess:@"Reauthenticate with Game Center succeeded."]; |
| 1847 | + } |
| 1848 | + [self showTypicalUIForUserUpdateResultsWithTitle:@"Reauthenticate Error" error:error]; |
| 1849 | + }]; |
| 1850 | + }]; |
| 1851 | + } |
| 1852 | + }]; |
| 1853 | +} |
1729 | 1854 | /** @fn signInEmailPassword
|
1730 | 1855 | @brief Invoked when "Sign in with Email/Password" row is pressed.
|
1731 | 1856 | */
|
|
0 commit comments