summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/LoginViewController.h6
-rw-r--r--Juick/ViewControllers/LoginViewController.m23
2 files changed, 27 insertions, 2 deletions
diff --git a/Juick/ViewControllers/LoginViewController.h b/Juick/ViewControllers/LoginViewController.h
index 451a99c..fd8e78a 100644
--- a/Juick/ViewControllers/LoginViewController.h
+++ b/Juick/ViewControllers/LoginViewController.h
@@ -7,17 +7,19 @@
//
#import <UIKit/UIKit.h>
-
+#import "JJJAuthorizationField.h"
#import "User.h"
extern NSString * const UserChangedNotificationName;
-@interface LoginViewController : UIViewController
+API_AVAILABLE(ios(13.0))
+@interface LoginViewController : UIViewController<ASAuthorizationControllerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *currentUser;
@property (weak, nonatomic) IBOutlet UITextField *usernameField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@property (weak, nonatomic) IBOutlet UIButton *signOutButton;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
+@property (weak, nonatomic) IBOutlet JJJAuthorizationField *authorizationField;
- (IBAction)signoutPressed:(id)sender;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
@end
diff --git a/Juick/ViewControllers/LoginViewController.m b/Juick/ViewControllers/LoginViewController.m
index a0e9b97..de83fa4 100644
--- a/Juick/ViewControllers/LoginViewController.m
+++ b/Juick/ViewControllers/LoginViewController.m
@@ -28,6 +28,7 @@ NSString * const UserChangedNotificationName = @"UserSignedIn";
target:self action:@selector(doneSignIn)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
+ [self.authorizationField.button addTarget:self action:@selector(signInWithApple) forControlEvents:UIControlEventTouchUpInside];
}
- (void)viewWillAppear:(BOOL)animated {
@@ -64,6 +65,7 @@ NSString * const UserChangedNotificationName = @"UserSignedIn";
- (void)refreshState {
if ([AppDelegate shared].api.currentUser) {
self.title = @"Profile";
+ [self.authorizationField setHidden:YES];
[self.usernameField setHidden:YES];
[self.passwordField setHidden:YES];
[self.currentUser setHidden:NO];
@@ -82,6 +84,7 @@ NSString * const UserChangedNotificationName = @"UserSignedIn";
} else {
self.title = @"Sign in";
self.imageView.image = [UIImage imageNamed:@"Splash"];
+ [self.authorizationField setHidden:NO];
[self.usernameField setHidden:NO];
[self.passwordField setHidden:NO];
[self.currentUser setHidden:YES];
@@ -96,4 +99,24 @@ NSString * const UserChangedNotificationName = @"UserSignedIn";
[[NSNotificationCenter defaultCenter] postNotificationName:UserChangedNotificationName object:nil];
}];
}
+
+- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization {
+ NSLog(@"");
+}
+
+- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error {
+ NSLog(@"");
+}
+
+-(void) signInWithApple {
+ ASAuthorizationAppleIDProvider *appleIDProvider = [ASAuthorizationAppleIDProvider new];
+ ASAuthorizationAppleIDRequest *request = [appleIDProvider createRequest];
+ request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
+
+ ASAuthorizationController *authorizationController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
+ authorizationController.delegate = self;
+ authorizationController.presentationContextProvider = self;
+ [authorizationController performRequests];
+}
+
@end