YBHomeRedObj.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // YBHomeRedObj.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2023/1/13.
  6. // Copyright © 2023 cat. All rights reserved.
  7. //
  8. #import "YBHomeRedObj.h"
  9. @implementation YBHomeRedObj
  10. static YBHomeRedObj *_redInstance = nil;
  11. +(instancetype)redInstance{
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. _redInstance = [[super allocWithZone:NULL]init];
  15. _redInstance.lookCount = 0;
  16. });
  17. return _redInstance;
  18. }
  19. + (instancetype)allocWithZone:(struct _NSZone *)zone{
  20. return [self redInstance];
  21. }
  22. -(void)initWithTimer{
  23. if(!_lookTimer){
  24. _lookTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(lookTimerStart) userInfo:nil repeats:YES];
  25. }
  26. }
  27. -(void)lookTimerStart{
  28. _lookCount ++;
  29. if (_lookCount >= 60) {
  30. _lookCount = 60;
  31. [self timerPause];
  32. [self getWatchVideoAward];
  33. }else{
  34. CGFloat timeS = (CGFloat)1/60;
  35. _startFloattime +=timeS;
  36. // if([self.delegate respondsToSelector:@selector(homeRedReloadTime:)]){
  37. // [self.delegate homeRedReloadTime:_startFloattime];
  38. // }
  39. if(self.startEvent){
  40. self.startEvent(_startFloattime);
  41. }
  42. // progressView.progress =_startFloattime;
  43. }
  44. NSLog(@"yblookvc-------:%d",_lookCount);
  45. }
  46. -(void)timePause{
  47. [self timerPause];
  48. }
  49. -(void)timerPause{
  50. if (_lookTimer) {
  51. [_lookTimer setFireDate:[NSDate distantFuture]];
  52. }
  53. }
  54. -(void)timerBegin{
  55. if (_lookTimer) {
  56. [_lookTimer setFireDate:[NSDate date]];
  57. }
  58. }
  59. -(void)timerEnd{
  60. if (_lookTimer) {
  61. [_lookTimer invalidate];
  62. _lookTimer = nil;
  63. }
  64. }
  65. -(void)timeGo{
  66. [self timerBegin];
  67. }
  68. -(void)getWatchVideoAward{
  69. NSDictionary *dic = @{@"uid":[Config getOwnID],@"token":[Config getOwnToken]};
  70. [YBNetworking postWithUrl:@"Video.watchVideoAward" Dic:dic Suc:^(int code, id info, NSString *msg) {
  71. if(code == 0){
  72. NSDictionary *infos = [info firstObject];
  73. if ([minstr([infos valueForKey:@"continue_receive"]) isEqual:@"1"]) {
  74. _lookCount = 0;
  75. _startFloattime = 0.0f;
  76. [self timerBegin];
  77. }
  78. }else{
  79. [self timerEnd];
  80. }
  81. [MBProgressHUD showError:msg];
  82. } Fail:^(id fail) {
  83. }];
  84. }
  85. @end