From 1f3e08f107064fa429c6aa2a26702f6e63a791f0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 20 Mar 2019 01:50:48 +0300 Subject: [AppDelegate shared] --- Juick/AppDelegate.h | 2 ++ Juick/AppDelegate.m | 4 ++++ Juick/ViewControllers/DialogsViewController.m | 9 ++++----- Juick/ViewControllers/DiscoverViewController.m | 10 ++++------ Juick/ViewControllers/LoginViewController.m | 3 +-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Juick/AppDelegate.h b/Juick/AppDelegate.h index a493664..931cf0b 100644 --- a/Juick/AppDelegate.h +++ b/Juick/AppDelegate.h @@ -14,6 +14,8 @@ -(void) registerForRemoteNotifications; ++(AppDelegate *) shared; + @property (strong, nonatomic) NSNumber *pushedThread; @property (strong, nonatomic) NSString *pushedUname; diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index aa3a48b..5aff686 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -125,4 +125,8 @@ self.pushedUname = userInfo[@"uname"]; } ++(AppDelegate *) shared { + return (AppDelegate *)[UIApplication sharedApplication].delegate; +} + @end diff --git a/Juick/ViewControllers/DialogsViewController.m b/Juick/ViewControllers/DialogsViewController.m index 05f0958..c4ace7f 100644 --- a/Juick/ViewControllers/DialogsViewController.m +++ b/Juick/ViewControllers/DialogsViewController.m @@ -66,11 +66,10 @@ -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"chatSegue"]) { NSString *uname; - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - if ([appDelegate.pushedUname length] > 0) { - uname = [appDelegate.pushedUname copy]; - appDelegate.pushedThread = nil; - appDelegate.pushedUname = nil; + if ([[AppDelegate shared].pushedUname length] > 0) { + uname = [[AppDelegate shared].pushedUname copy]; + [AppDelegate shared].pushedThread = nil; + [AppDelegate shared].pushedUname = nil; } else { Chat *chat = [self.chats objectAtIndex:[self.tableView indexPathForSelectedRow].row]; uname = chat.uname; diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index 092c19c..27b273b 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -16,7 +16,6 @@ @interface DiscoverViewController () -@property(nonatomic, strong) AppDelegate *appDelegate; @property NSString *selectedUser; @end @@ -49,7 +48,6 @@ [self refreshData]; } [super viewDidLoad]; - self.appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { @@ -76,10 +74,10 @@ if ([segue.identifier isEqual: @"threadViewSegue"]) { NSNumber *mid; BOOL scrollToEnd = NO; - if (self.appDelegate.pushedThread != nil) { - mid = [self.appDelegate.pushedThread copy]; - self.appDelegate.pushedThread = nil; - self.appDelegate.pushedUname = nil; + if ([AppDelegate shared].pushedThread != nil) { + mid = [[AppDelegate shared].pushedThread copy]; + [AppDelegate shared].pushedThread = nil; + [AppDelegate shared].pushedUname = nil; scrollToEnd = YES; } else { Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row]; diff --git a/Juick/ViewControllers/LoginViewController.m b/Juick/ViewControllers/LoginViewController.m index c0b1a0d..e1b12f2 100644 --- a/Juick/ViewControllers/LoginViewController.m +++ b/Juick/ViewControllers/LoginViewController.m @@ -62,8 +62,7 @@ NSString *password = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]; [[APIClient sharedClient].manager.requestSerializer setAuthorizationHeaderFieldWithUsername:username password:password]; - AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - [app registerForRemoteNotifications]; + [[AppDelegate shared] registerForRemoteNotifications]; CATransition* transition = [CATransition animation]; transition.duration = 0.3; transition.type = kCATransitionFade; -- cgit v1.2.3