diff options
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/Helpers/JJJAuthorizationField.h | 19 | ||||
-rw-r--r-- | Juick/Helpers/JJJAuthorizationField.m | 38 | ||||
-rw-r--r-- | Juick/Juick.entitlements | 4 | ||||
-rw-r--r-- | Juick/Main.storyboard | 19 | ||||
-rw-r--r-- | Juick/Model/Message.m | 4 | ||||
-rw-r--r-- | Juick/ViewControllers/LoginViewController.h | 6 | ||||
-rw-r--r-- | Juick/ViewControllers/LoginViewController.m | 23 |
7 files changed, 103 insertions, 10 deletions
diff --git a/Juick/Helpers/JJJAuthorizationField.h b/Juick/Helpers/JJJAuthorizationField.h new file mode 100644 index 0000000..d5118e0 --- /dev/null +++ b/Juick/Helpers/JJJAuthorizationField.h @@ -0,0 +1,19 @@ +// +// JJJAuthorizationField.h +// Juick +// +// Created by Vitaly Takmazov on 15.05.2020. +// Copyright © 2020 com.juick. All rights reserved. +// + +#import <UIKit/UIKit.h> +#import <AuthenticationServices/AuthenticationServices.h> + +NS_ASSUME_NONNULL_BEGIN +IB_DESIGNABLE +API_AVAILABLE(ios(13.0)) +@interface JJJAuthorizationField : UIView +@property (nonatomic, strong) IBInspectable ASAuthorizationAppleIDButton *button; +@end + +NS_ASSUME_NONNULL_END diff --git a/Juick/Helpers/JJJAuthorizationField.m b/Juick/Helpers/JJJAuthorizationField.m new file mode 100644 index 0000000..1173d8b --- /dev/null +++ b/Juick/Helpers/JJJAuthorizationField.m @@ -0,0 +1,38 @@ +// +// JJJAuthorizationField.m +// Juick +// +// Created by Vitaly Takmazov on 15.05.2020. +// Copyright © 2020 com.juick. All rights reserved. +// + +#import "JJJAuthorizationField.h" + +@implementation JJJAuthorizationField + +- (instancetype)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (self) { + [self setup]; + } + return self; +} + +- (void)setup +{ + self.button = [ASAuthorizationAppleIDButton new]; + [self addSubview:self.button]; + self.translatesAutoresizingMaskIntoConstraints = NO; + self.button.translatesAutoresizingMaskIntoConstraints = NO; + [NSLayoutConstraint activateConstraints:@[ + [self.widthAnchor constraintEqualToConstant:250.0], + [self.heightAnchor constraintEqualToConstant:46.0], + [self.button.topAnchor constraintEqualToAnchor:self.button.superview.topAnchor constant:0.0], + [self.button.bottomAnchor constraintEqualToAnchor:self.self.button.superview.bottomAnchor constant:0.0], + [self.button.trailingAnchor constraintEqualToAnchor:self.self.button.superview.trailingAnchor constant:0.0], + [self.button.leadingAnchor constraintEqualToAnchor:self.self.button.superview.leadingAnchor constant:0.0] + ]]; +} + +@end diff --git a/Juick/Juick.entitlements b/Juick/Juick.entitlements index d8c59dc..0a01181 100644 --- a/Juick/Juick.entitlements +++ b/Juick/Juick.entitlements @@ -4,6 +4,10 @@ <dict> <key>aps-environment</key> <string>development</string> + <key>com.apple.developer.applesignin</key> + <array> + <string>Default</string> + </array> <key>com.apple.developer.associated-domains</key> <array> <string>webcredentials:juick.com</string> diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index 5d99c97..eba0978 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -100,19 +100,23 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <stackView opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" axis="vertical" spacing="24" translatesAutoresizingMaskIntoConstraints="NO" id="axR-g5-sfd"> - <rect key="frame" x="12" y="68" width="351" height="313.5"/> + <rect key="frame" x="12" y="68" width="351" height="555"/> <subviews> <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Splash.png" translatesAutoresizingMaskIntoConstraints="NO" id="ohW-YQ-JZL"> <rect key="frame" x="0.0" y="0.0" width="351" height="96"/> </imageView> + <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="scE-F3-7PK" customClass="JJJAuthorizationField"> + <rect key="frame" x="0.0" y="120" width="351" height="217.5"/> + <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> + </view> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Anonymous" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PUg-SX-ZdC" userLabel="Current user"> - <rect key="frame" x="0.0" y="120" width="351" height="20.5"/> + <rect key="frame" x="0.0" y="361.5" width="351" height="20.5"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <color key="textColor" name="Title"/> <nil key="highlightedColor"/> </label> <textField opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="251" verticalCompressionResistancePriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="rhb-m4-21c"> - <rect key="frame" x="0.0" y="164.5" width="351" height="34"/> + <rect key="frame" x="0.0" y="406" width="351" height="34"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <textInputTraits key="textInputTraits" returnKeyType="next" textContentType="username"/> <userDefinedRuntimeAttributes> @@ -120,15 +124,15 @@ </userDefinedRuntimeAttributes> </textField> <textField opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="251" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="T1M-x6-Ghc"> - <rect key="frame" x="0.0" y="222.5" width="351" height="34"/> + <rect key="frame" x="0.0" y="464" width="351" height="34"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <textInputTraits key="textInputTraits" returnKeyType="go" secureTextEntry="YES" textContentType="password"/> <userDefinedRuntimeAttributes> <userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="Password..."/> </userDefinedRuntimeAttributes> </textField> - <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gPQ-xI-b5J"> - <rect key="frame" x="0.0" y="280.5" width="351" height="33"/> + <button opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="252" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gPQ-xI-b5J"> + <rect key="frame" x="0.0" y="522" width="351" height="33"/> <color key="backgroundColor" name="Chat"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <state key="normal" title="Sign out"> @@ -146,11 +150,14 @@ <constraint firstItem="fue-ZI-ech" firstAttribute="trailing" secondItem="axR-g5-sfd" secondAttribute="trailing" constant="12" id="CP5-In-mwY"/> <constraint firstItem="axR-g5-sfd" firstAttribute="leading" secondItem="fue-ZI-ech" secondAttribute="leading" constant="12" id="YIV-CU-Vyy"/> <constraint firstItem="axR-g5-sfd" firstAttribute="top" secondItem="fue-ZI-ech" secondAttribute="top" constant="12" id="ZUC-uk-RH7"/> + <constraint firstItem="fue-ZI-ech" firstAttribute="bottom" secondItem="axR-g5-sfd" secondAttribute="bottom" constant="24" id="c0m-YD-3ie"/> </constraints> <viewLayoutGuide key="safeArea" id="fue-ZI-ech"/> </view> <navigationItem key="navigationItem" id="QaM-45-gms"/> <connections> + <outlet property="authorizationField" destination="scE-F3-7PK" id="1eK-ef-9tg"/> + <outlet property="bottomConstraint" destination="c0m-YD-3ie" id="UUe-qL-YrM"/> <outlet property="currentUser" destination="PUg-SX-ZdC" id="hEq-3R-Dxu"/> <outlet property="imageView" destination="ohW-YQ-JZL" id="dxm-uI-j6a"/> <outlet property="passwordField" destination="T1M-x6-Ghc" id="y4o-Hf-w22"/> diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m index d39be54..afc01af 100644 --- a/Juick/Model/Message.m +++ b/Juick/Model/Message.m @@ -20,8 +20,8 @@ message.repliesBy = jsonData[@"repliesby"]; message.user = [User fromJSON:jsonData[@"user"]]; message.timestamp = jsonData[@"timestamp"]; - message.service = jsonData[@"service"]; - message.unread = jsonData[@"unread"]; + message.service = [jsonData[@"service"] boolValue]; + message.unread = [jsonData[@"unread"] boolValue]; message.tags = jsonData[@"tags"]; NSMutableArray *entitiesArray = [NSMutableArray new]; for (NSDictionary *entityData in jsonData[@"entities"]) { 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 |