SPSBOpenPopupManager.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // SPSBOpenPopupManager.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/26.
  6. //
  7. #import "SPSBOpenPopupManager.h"
  8. #import <JXHMacro.h>
  9. #import <JXHGeneralTools.h>
  10. #import "SPSBGeneralManager.h"
  11. #import "SPSBPopupViewController.h"
  12. static NSMutableArray<SPSBOpenPopupModel *> *_spsb_popupArray = nil;
  13. static bool _spsb_canPopup = true;
  14. static bool _spsb_beginPoput = false;
  15. @implementation SPSBOpenPopupModel @end
  16. @implementation SPSBOpenPopupManager
  17. + (void)insertPopupAtFirst:(SPSBOpenPopupModel *)popup {
  18. if (!_spsb_popupArray) {
  19. _spsb_popupArray = NSMutableArray.new;
  20. }
  21. [_spsb_popupArray insertObject:popup atIndex:0];
  22. [self check];
  23. }
  24. + (void)insertPopup:(SPSBOpenPopupModel *)popup {
  25. if (!_spsb_popupArray) {
  26. _spsb_popupArray = NSMutableArray.new;
  27. }
  28. [_spsb_popupArray addObject:popup];
  29. [self check];
  30. }
  31. + (void)beginPopup {
  32. _spsb_beginPoput = true;
  33. [self check];
  34. }
  35. + (void)check {
  36. if (!_spsb_beginPoput) return;
  37. dispatch_main_async_safe(^{
  38. if (!_spsb_canPopup || _spsb_popupArray.count == 0) return;
  39. _spsb_canPopup = false;
  40. [self pop];
  41. });
  42. }
  43. + (void)pop {
  44. SPSBOpenPopupModel *model = _spsb_popupArray[0];
  45. [_spsb_popupArray removeObjectAtIndex:0];
  46. [jxh_findPresentedViewControllerStartingFrom(spsb_keyWindow().rootViewController) presentViewController:model.spsb_popup animated:false completion:^{
  47. if (!model.spsb_stopPopup) {
  48. _spsb_canPopup = true;
  49. [self check];
  50. }
  51. }];
  52. }
  53. @end