From 2c046a01003665aa78ca8f069c215ba1420c76cc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 1 Dec 2021 17:43:49 +0300 Subject: Present login error correctly on iPad/Mac --- Juick/Helpers/User+UIView.h | 2 +- Juick/Helpers/User+UIView.m | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'Juick/Helpers') diff --git a/Juick/Helpers/User+UIView.h b/Juick/Helpers/User+UIView.h index d2f75ce..dcd7047 100644 --- a/Juick/Helpers/User+UIView.h +++ b/Juick/Helpers/User+UIView.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @interface User (UIView) -+ (void) throwUnableToLogin:(UIViewController *)view error:(NSError *)error path:(NSString *)path params:(NSDictionary * _Nullable)params; ++ (void) throwUnableToLogin:(UIViewController *)parentViewController sourceView:(UIView *)sourceView error:(NSError *)error path:(NSString *)path params:(NSDictionary * _Nullable)params; @end diff --git a/Juick/Helpers/User+UIView.m b/Juick/Helpers/User+UIView.m index 4fb0bc3..2235cef 100644 --- a/Juick/Helpers/User+UIView.m +++ b/Juick/Helpers/User+UIView.m @@ -10,19 +10,18 @@ @implementation User (UIView) -+(void) throwUnableToLogin:(UIViewController *)view error:(NSError *)error path:(NSString *)path params:(NSDictionary *)params { ++(void) throwUnableToLogin:(UIViewController *)parentViewController sourceView:(UIView *)sourceView error:(NSError *)error path:(NSString *)path params:(NSDictionary *)params { UIAlertController *alert = [UIAlertController new]; NSString *title = error.userInfo[@"url"] ? error.userInfo[@"url"] : @"Something went wrong"; [alert setTitle:title]; [alert setMessage:[NSString stringWithFormat:@"err: %@, path: %@, params: %@", error.localizedDescription, path, params]]; [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]]; - UIPopoverPresentationController *popover = [alert popoverPresentationController]; - if (popover) { - popover.sourceView = view.view; - popover.sourceRect = CGRectMake(CGRectGetMidX(view.view.bounds), CGRectGetMidY(view.view.bounds), 0, 0); - popover.permittedArrowDirections = UIPopoverArrowDirectionDown; + UIPopoverPresentationController *popopverPresenter = [alert popoverPresentationController]; + if (popopverPresenter) { + popopverPresenter.sourceView = sourceView; + popopverPresenter.sourceRect = CGRectMake(CGRectGetMidX(sourceView.bounds), CGRectGetMidY(sourceView.bounds), 0, 0); } - [view presentViewController:alert animated:YES completion:nil]; + [parentViewController presentViewController:alert animated:YES completion:nil]; } @end -- cgit v1.2.3