RQCycleScrollView.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // RQCycleScrollView.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2021/6/24.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import "RQCycleScrollView.h"
  9. #import "WXApiManager.h"
  10. #import "WechatAuthSDK.h"
  11. @interface RQCycleScrollView () <SDCycleScrollViewDelegate, WXApiManagerDelegate, WechatAuthAPIDelegate>
  12. @property (nonatomic, readwrite, strong) SDCycleScrollView *cycleScrollView;
  13. @property (nonatomic, readwrite, strong) NSMutableArray *newImageURLStringsGroup;
  14. @property (nonatomic, readwrite, strong) NSMutableArray *newDataArr;
  15. @end
  16. @implementation RQCycleScrollView
  17. #pragma mark - PublicMethods
  18. - (instancetype)initWithFrame:(CGRect)frame dataArr:(NSArray *)dataArr {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self addSubview:self.cycleScrollView];
  22. self.cycleScrollView.size = self.size;
  23. [self dataProcessWithDataArr:dataArr];
  24. [WXApiManager sharedManager].delegate = self;
  25. }
  26. return self;
  27. }
  28. - (void)updateDataArr:(NSArray *)dataArr {
  29. [self dataProcessWithDataArr:dataArr];
  30. }
  31. #pragma mark - PrivateMethods
  32. - (void)dataProcessWithDataArr:(NSArray *)dataArr {
  33. if (self.newDataArr.count > 0) {
  34. [self.newDataArr removeAllObjects];
  35. }
  36. [self.newDataArr addObjectsFromArray:dataArr];
  37. [[self.newDataArr.rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSDictionary *dic) {
  38. [self.newImageURLStringsGroup addObject:dic[@"IMG"]];
  39. } completed:^{
  40. self.cycleScrollView.imageURLStringsGroup = self.newImageURLStringsGroup;
  41. }];
  42. }
  43. #pragma mark - SDCycleScrollViewDelegate
  44. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  45. // NSLog(@"---点击了第%ld张图片----%@", (long)index, self.newDataArr[index][@"LOCATION"]);
  46. //
  47. // NSDictionary *dic = self.newDataArr[index];
  48. // [RQ_SHARE_FUNCTION saveObjectWithObject:dic ForKey:@"currentSelectDic"];
  49. //
  50. // NSString *skipType = dic[@"OPENTYPE"];
  51. // if ([skipType isEqualToString:@"1"]) {
  52. // [RQ_SHARE_FUNCTION gotoWebViewWithUrlStr:dic[@"URL"]];
  53. // }else{
  54. // if ([dic[@"ADTYPE"] isEqualToString:@"2"]) {
  55. // [RQ_SHARE_FUNCTION miniwithUserName:dic[@"URL"] path:dic[@"AI_XCX_URL"]? : @""];
  56. // } else if ([dic[@"ADTYPE"] isEqualToString:@"1"]) {
  57. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:dic[@"URL"]] options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:nil];
  58. // } else if ([dic[@"ADTYPE"] isEqualToString:@"3"]) {
  59. //// [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
  60. //// NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
  61. //// }];
  62. //// return;
  63. // WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
  64. // req.scene = 1;
  65. // req.templateId = @"1iZwYeI2QtSXZ3rTRkQ42wgRkd7NSINzem8R-LvtHYw";
  66. // req.reserved = @"";
  67. // [WXApi sendReq:req completion:nil];
  68. // }
  69. // }
  70. }
  71. #pragma mark - WXApiManagerDelegate
  72. - (void)managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *)response {
  73. // NSDictionary *currentSelectDic = [RQ_SHARE_FUNCTION getObjectWithKey:@"currentSelectDic"];
  74. // NSMutableArray *arr = [NSMutableArray array];
  75. // [arr property:defUser.userDict[@"outId"] forKey:@"StudentoutID"];
  76. // [jiaPeiManager requestAnythingWithURL:@"getToken" array:arr data:nil completion:^(NSDictionary *dic) {
  77. // if ([dic[@"code"] intValue] == 0) {
  78. // [jiaPeiManager requestAnythingWithURL:[NSString stringWithFormat:@"https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=%@",dic[@"body"]] array:@[
  79. // @{@"touser" : response.openId? : @""},
  80. // @{@"template_id" : response.templateId? : @""},
  81. // @{@"url" : currentSelectDic[@"URL"]? : @"https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzk0MTI1ODAyMA==#wechat_redirect"},
  82. // @{@"scene" : [NSNumber numberWithInt:response.scene]},
  83. // @{@"title" : currentSelectDic[@"TITLE"]? : @"消息"},
  84. // @{@"data" : @{@"content":@{@"color":@"#173177",@"value":currentSelectDic[@"AI_CONTENT"]? : @"点击关注公众号"}}}
  85. // ].mutableCopy data:nil completion:^(NSDictionary *dict) {
  86. // if ([dict[@"errcode"] integerValue] == 0) {
  87. // dispatch_async(dispatch_get_main_queue(), ^{
  88. // ShowMsg(@"成功");
  89. // });
  90. // } else {
  91. // ShowMsg(@"失败");
  92. // }
  93. // }];
  94. // } else {
  95. // ShowMsg(@"获取token失败");
  96. // }
  97. // }];
  98. }
  99. #pragma mark - LazyLoad
  100. - (SDCycleScrollView *)cycleScrollView {
  101. if (!_cycleScrollView) {
  102. _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SHARE_FUNCTION.RQADViewHeight) delegate:self placeholderImage:[UIImage imageNamed:@"subject_main_banner"]];
  103. _cycleScrollView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
  104. _cycleScrollView.autoScrollTimeInterval = 5;
  105. _cycleScrollView.backgroundColor = UIColor.whiteColor;
  106. }
  107. return _cycleScrollView;
  108. }
  109. - (NSMutableArray *)newImageURLStringsGroup {
  110. if (!_newImageURLStringsGroup) {
  111. _newImageURLStringsGroup = [NSMutableArray array];
  112. }
  113. return _newImageURLStringsGroup;
  114. }
  115. - (NSMutableArray *)newDataArr {
  116. if (!_newDataArr) {
  117. _newDataArr = [NSMutableArray array];
  118. }
  119. return _newDataArr;
  120. }
  121. @end