BasicViewController.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // BasicViewController.m
  3. // RA Image
  4. //
  5. // Created by Jack on 2017/4/27.
  6. // Copyright © 2017年 USAI. All rights reserved.
  7. //
  8. #import "BasicViewController.h"
  9. NSString *const LogoutNotification = @"LogouNotification";
  10. @interface BasicViewController ()
  11. @end
  12. @implementation BasicViewController
  13. - (NSNotificationCenter *)notificationCenter {
  14. return [NSNotificationCenter defaultCenter];
  15. }
  16. - (void)dealloc {
  17. [self.notificationCenter removeObserver:self];
  18. }
  19. - (void)registNofitication {
  20. [self.notificationCenter addObserver:self selector:@selector(userLogout:) name:LogoutNotification object:nil];
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. }
  26. - (void)didReceiveMemoryWarning {
  27. [super didReceiveMemoryWarning];
  28. // Dispose of any resources that can be recreated.
  29. }
  30. - (id)userDefaultsValue:(NSString *)key {
  31. return [[NSUserDefaults standardUserDefaults] valueForKey:key];
  32. }
  33. - (void)setUserDefaultsValue:(id)value forKey:(NSString *)key {
  34. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  35. [userDefaults setValue:value forKey:key];
  36. [userDefaults synchronize];
  37. }
  38. - (void)userLogout:(NSNotification *)notification {
  39. if (self.presentedViewController) {
  40. [self dismissViewControllerAnimated:NO completion:nil];
  41. return;
  42. }
  43. if (self.navigationController) {
  44. [self.navigationController popToRootViewControllerAnimated:NO];
  45. }
  46. }
  47. @end