GlobalData.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // GlobalData.m
  3. // ChinaDream
  4. //
  5. // Created by zhangfeng on 12-11-26.
  6. // Copyright (c) 2012年 eastedge. All rights reserved.
  7. //
  8. #import "GlobalData.h"
  9. UINavigationController *GB_Nav = nil;
  10. //int GB_OpenWaitShowCount = 0;
  11. //float GB_StartYCoordinate = 0.0f;
  12. @implementation GlobalData
  13. @synthesize GB_Key = _GB_Key;
  14. @synthesize GB_UserModel = _GB_UserModel;
  15. //@synthesize GB_CompanyModel = _GB_CompanyModel;
  16. //@synthesize GB_MarketModules = _GB_MarketModules;
  17. #pragma mark 实现单例
  18. SYNTHESIZE_SINGLETONE_FOR_CLASS(GlobalData);
  19. - (instancetype)init{
  20. self = [super init];
  21. if (self) {
  22. //初始化状态栏
  23. self.statusBarStyle = UIStatusBarStyleLightContent;
  24. }
  25. return self;
  26. }
  27. #pragma mark lazy init
  28. //set get key
  29. - (void)setGB_Key:(NSString *)GB_Key{
  30. [GlobalMethod writeStr:GB_Key!=nil?GB_Key:@"" forKey:LOCAL_KEY];
  31. _GB_Key = GB_Key;
  32. }
  33. - (NSString*)GB_Key{
  34. if (!isStr(_GB_Key)){
  35. _GB_Key = [GlobalMethod readStrFromUser:LOCAL_KEY];
  36. }
  37. return _GB_Key;
  38. }
  39. //set get userModel
  40. - (void)setGB_UserModel:(ModelUser *)GB_UserModel{
  41. [GlobalMethod writeStr:GB_UserModel != nil?[GlobalMethod exchangeModelToJson:GB_UserModel]:@"" forKey:LOCAL_USERMODEL];
  42. _GB_UserModel = GB_UserModel;
  43. //保存手机号
  44. if (isStr(GB_UserModel.phone)) {
  45. NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
  46. [user setObject:GB_UserModel.phone forKey:LOCAL_PHONE];
  47. [user synchronize];
  48. }
  49. if (GB_UserModel) {
  50. [[NSNotificationCenter defaultCenter]postNotificationName:NOTICE_SELFMODEL_CHANGE object:nil];
  51. }
  52. }
  53. + (void)saveUserModel{
  54. [GlobalData sharedInstance].GB_UserModel = [GlobalData sharedInstance].GB_UserModel;
  55. }
  56. - (ModelUser *)GB_UserModel{
  57. if (_GB_UserModel.phone == 0) {
  58. NSDictionary * dicItem = [GlobalMethod exchangeStringToDic:[GlobalMethod readStrFromUser:LOCAL_USERMODEL]];
  59. _GB_UserModel = [ModelUser modelObjectWithDictionary:dicItem];
  60. }
  61. return _GB_UserModel;
  62. }
  63. //set Notice View
  64. - (NoticeView *)GB_NoticeView{
  65. if (_GB_NoticeView == nil) {
  66. _GB_NoticeView = [NoticeView new];
  67. }
  68. return _GB_NoticeView;
  69. }
  70. @end