diff options
-rw-r--r-- | Juick.xcodeproj/project.pbxproj | 6 | ||||
-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 |
8 files changed, 109 insertions, 10 deletions
diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index dcb9060..1c88425 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 776C41BD1FD3EF180063B82E /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41BB1FD3EF180063B82E /* MessageCell.m */; }; 776C41BE1FD3EF180063B82E /* MessageCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 776C41BC1FD3EF180063B82E /* MessageCell.xib */; }; 776C41C11FD3FF6E0063B82E /* FeedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41C01FD3FF6E0063B82E /* FeedViewController.m */; }; + 7779B38F246EC88D003EF2F6 /* JJJAuthorizationField.m in Sources */ = {isa = PBXBuildFile; fileRef = 7779B38E246EC88D003EF2F6 /* JJJAuthorizationField.m */; }; 778560602343D24E00BB37A2 /* NSData+Hex.m in Sources */ = {isa = PBXBuildFile; fileRef = 7785605F2343D24E00BB37A2 /* NSData+Hex.m */; }; 778560632344CF6F00BB37A2 /* JuickNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 778560622344CF6F00BB37A2 /* JuickNavigationController.m */; }; 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77975A1C182B6E9A00410C2B /* NewPostViewController.m */; }; @@ -157,6 +158,8 @@ 776C41BC1FD3EF180063B82E /* MessageCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageCell.xib; sourceTree = "<group>"; }; 776C41BF1FD3FF6E0063B82E /* FeedViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FeedViewController.h; sourceTree = "<group>"; }; 776C41C01FD3FF6E0063B82E /* FeedViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FeedViewController.m; sourceTree = "<group>"; }; + 7779B38D246EC88D003EF2F6 /* JJJAuthorizationField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JJJAuthorizationField.h; sourceTree = "<group>"; }; + 7779B38E246EC88D003EF2F6 /* JJJAuthorizationField.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JJJAuthorizationField.m; sourceTree = "<group>"; }; 7785605E2343D24E00BB37A2 /* NSData+Hex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Hex.h"; sourceTree = "<group>"; }; 7785605F2343D24E00BB37A2 /* NSData+Hex.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Hex.m"; sourceTree = "<group>"; }; 778560612344CF6F00BB37A2 /* JuickNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JuickNavigationController.h; sourceTree = "<group>"; }; @@ -382,6 +385,8 @@ 7785605F2343D24E00BB37A2 /* NSData+Hex.m */, 774746AB239F82A10001C7F9 /* NSDate+TimeAgo.h */, 774746AC239F82A10001C7F9 /* NSDate+TimeAgo.m */, + 7779B38D246EC88D003EF2F6 /* JJJAuthorizationField.h */, + 7779B38E246EC88D003EF2F6 /* JJJAuthorizationField.m */, ); path = Helpers; sourceTree = "<group>"; @@ -595,6 +600,7 @@ 7761133821766A3000D350CD /* ContentLoadingCell.m in Sources */, 77E61A5E1FD4682B00B4E304 /* QuoteView.m in Sources */, 77317BBC181BBE8500D60005 /* AppDelegate.m in Sources */, + 7779B38F246EC88D003EF2F6 /* JJJAuthorizationField.m in Sources */, 776C41C11FD3FF6E0063B82E /* FeedViewController.m in Sources */, 77FCADDF1D6A50DA00CBA649 /* API.m in Sources */, 77A0954A181F1F25002BDECD /* Message.m in Sources */, 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 |