Commit 2aa6ea9b09411a9d31ff94cf2e0172e460f5f74b
1 parent
66b54196
消息通知功能开发
Showing
10 changed files
with
218 additions
and
11 deletions
CNLiveCMineModule.podspec
CNLiveCMineModule/Classes/CNCSubMine/View/CNMessageNoteFooterView.h
0 → 100644
CNLiveCMineModule/Classes/CNCSubMine/View/CNMessageNoteFooterView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNMessageNoteFooterView.m | |
| 3 | +// CNLiveCMineModule | |
| 4 | +// | |
| 5 | +// Created by iOS on 2022/12/9. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import "CNMessageNoteFooterView.h" | |
| 9 | + | |
| 10 | +@interface CNMessageNoteFooterView () | |
| 11 | +@property (nonatomic, strong)UILabel *label; | |
| 12 | +@end | |
| 13 | + | |
| 14 | +@implementation CNMessageNoteFooterView | |
| 15 | +- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{ | |
| 16 | + if (self = [super initWithReuseIdentifier:reuseIdentifier]) { | |
| 17 | + self.contentView.backgroundColor = UIColorHex(#F2F2F2); | |
| 18 | + [self.contentView addSubview:self.label]; | |
| 19 | + [self.label mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 20 | + make.left.equalTo(self).offset(18); | |
| 21 | + make.right.equalTo(self).offset(-18); | |
| 22 | + make.top.equalTo(self).offset(10); | |
| 23 | + make.bottom.equalTo(self); | |
| 24 | + }]; | |
| 25 | + } | |
| 26 | + return self; | |
| 27 | +} | |
| 28 | + | |
| 29 | +#pragma mark - Getting | |
| 30 | +-(UILabel *)label{ | |
| 31 | + if (!_label) { | |
| 32 | + _label = [[UILabel alloc] init]; | |
| 33 | + _label.font = UIFontMake(14); | |
| 34 | + _label.textColor = UIColorHex(#999999); | |
| 35 | + _label.numberOfLines = 2; | |
| 36 | + _label.text = @"关闭后你将不会在下拉通知看到该类型的消息,但在网家家内会显示红点。"; | |
| 37 | + } | |
| 38 | + return _label; | |
| 39 | +} | |
| 40 | +@end | ... | ... |
CNLiveCMineModule/Classes/CNCSubMine/View/CNMessgeNoteCell.m
| ... | ... | @@ -14,10 +14,11 @@ |
| 14 | 14 | @end |
| 15 | 15 | |
| 16 | 16 | @implementation CNMessgeNoteCell |
| 17 | -- (instancetype)initWithFrame:(CGRect)frame{ | |
| 18 | - if (self = [super initWithFrame:frame]) { | |
| 17 | +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ | |
| 18 | + if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { | |
| 19 | 19 | self.contentView.backgroundColor = [UIColor clearColor]; |
| 20 | 20 | self.backgroundColor = UIColorClear; |
| 21 | + self.selectionStyle = UITableViewCellSelectionStyleNone; | |
| 21 | 22 | [self.contentView addSubview:self.bgView]; |
| 22 | 23 | [self.bgView addSubview:self.titleLabel]; |
| 23 | 24 | [self.bgView addSubview:self.switchBtn]; |
| ... | ... | @@ -26,12 +27,18 @@ |
| 26 | 27 | make.top.equalTo(self).offset(10); |
| 27 | 28 | }]; |
| 28 | 29 | [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
| 29 | - | |
| 30 | + make.centerY.equalTo(self.bgView); | |
| 31 | + make.left.equalTo(self).offset(16); | |
| 32 | + }]; | |
| 33 | + [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 34 | + make.centerY.equalTo(self.bgView); | |
| 35 | + make.right.equalTo(self).offset(-8); | |
| 30 | 36 | }]; |
| 31 | 37 | } |
| 32 | 38 | return self; |
| 33 | 39 | } |
| 34 | 40 | - (void)switchValueChanged:(UISwitch *)sender{ |
| 41 | + self.model.state = sender.isOn; | |
| 35 | 42 | if (self.changeSwitchBlock) { |
| 36 | 43 | self.changeSwitchBlock(self.model); |
| 37 | 44 | } | ... | ... |
CNLiveCMineModule/Classes/CNCSubMine/ViewController/CNMessageNotesController.m
| ... | ... | @@ -8,8 +8,10 @@ |
| 8 | 8 | #import "CNMessageNotesController.h" |
| 9 | 9 | #import "CNMessgeNoteCell.h" |
| 10 | 10 | #import "CNCSubMinePresent.h" |
| 11 | +#import "CNMessageNoteFooterView.h" | |
| 11 | 12 | |
| 12 | -static NSString const*kCNMessgeNoteCellID = @"CNMessgeNoteCellID"; | |
| 13 | +static NSString const *kCNMessgeNoteCellID = @"CNMessgeNoteCellID"; | |
| 14 | +static NSString const *kCNMessageNoteFooterViewID = @"CNMessageNoteFooterViewID"; | |
| 13 | 15 | @interface CNMessageNotesController ()<UITableViewDelegate, UITableViewDataSource> |
| 14 | 16 | @property (nonatomic, strong)CNLiveNavigationBar *navigationBar; |
| 15 | 17 | @property (nonatomic, strong)UITableView *tableView; |
| ... | ... | @@ -43,12 +45,9 @@ static NSString const*kCNMessgeNoteCellID = @"CNMessgeNoteCellID"; |
| 43 | 45 | return 50; |
| 44 | 46 | } |
| 45 | 47 | - (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ |
| 46 | - UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(18, 10, kScreenWidth - 36, 40)]; | |
| 47 | - label.font = UIFontMake(14); | |
| 48 | - label.textColor = UIColorHex(#999999); | |
| 49 | - label.numberOfLines = 2; | |
| 50 | - label.text = @"关闭后你将不会在下拉通知看到该类型的消息,但在网家家内会显示红点。"; | |
| 51 | - return label; | |
| 48 | + CNMessageNoteFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kCNMessageNoteFooterViewID]; | |
| 49 | + | |
| 50 | + return view; | |
| 52 | 51 | } |
| 53 | 52 | #pragma mark - UITableViewDataSource |
| 54 | 53 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
| ... | ... | @@ -56,6 +55,12 @@ static NSString const*kCNMessgeNoteCellID = @"CNMessgeNoteCellID"; |
| 56 | 55 | } |
| 57 | 56 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ |
| 58 | 57 | CNMessgeNoteCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNMessgeNoteCellID]; |
| 58 | + cell.model = self.dataSource[indexPath.row]; | |
| 59 | + cell.changeSwitchBlock = ^(CNMessageNoteModel * _Nonnull model) { | |
| 60 | + [[CNLiveCMineService shareMineProtocol] updateSetupStatus:model.state userId:model.sys_type block:^(BOOL succ) { | |
| 61 | + | |
| 62 | + }]; | |
| 63 | + }; | |
| 59 | 64 | return cell; |
| 60 | 65 | } |
| 61 | 66 | #pragma mark - Getting |
| ... | ... | @@ -78,6 +83,7 @@ static NSString const*kCNMessgeNoteCellID = @"CNMessgeNoteCellID"; |
| 78 | 83 | _tableView.delegate = self; |
| 79 | 84 | _tableView.dataSource = self; |
| 80 | 85 | [_tableView registerClass:[CNMessgeNoteCell class] forCellReuseIdentifier:kCNMessgeNoteCellID]; |
| 86 | + [_tableView registerClass:[CNMessageNoteFooterView class] forHeaderFooterViewReuseIdentifier:kCNMessageNoteFooterViewID]; | |
| 81 | 87 | } |
| 82 | 88 | return _tableView; |
| 83 | 89 | } | ... | ... |
CNLiveCMineModule/Classes/CNLiveCMineProtocol.h
| ... | ... | @@ -150,6 +150,11 @@ TouchActionBlock:(void(^)(NSString * title))resultBlock; |
| 150 | 150 | @param completerBlock 返回支付结果 |
| 151 | 151 | */ |
| 152 | 152 | - (void)requestCNLiveContentPayViewForOrderPay:(CNOrderList *)orderModel FromVC:(UIViewController *)formVC CompleterBlock:(void(^)(CNLiveContentViewPayResult payResult))completerBlock; |
| 153 | +/// 更新推送设置 | |
| 154 | +/// @param on yes:关闭推送 No:打开推送 | |
| 155 | +/// @param userId 会话id | |
| 156 | +/// @param complete 请求完成回调 | |
| 157 | +- (void)updateSetupStatus:(BOOL)on userId:(NSString *)userId block:(void (^)(BOOL succ))complete; | |
| 153 | 158 | @end |
| 154 | 159 | |
| 155 | 160 | NS_ASSUME_NONNULL_END | ... | ... |
Example/CNLiveCMineModule.xcodeproj/project.pbxproj
| ... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 | 6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; }; |
| 30 | 30 | 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; }; |
| 31 | 31 | 7900B456277BF103001CC115 /* CNLiveCMineViewModuleImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 7900B455277BF103001CC115 /* CNLiveCMineViewModuleImpl.m */; }; |
| 32 | + 815C17A12942FA94005EB1E6 /* CNPushSetupManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 815C17A02942FA94005EB1E6 /* CNPushSetupManager.m */; }; | |
| 32 | 33 | 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; |
| 33 | 34 | 88731B515F7A0496959F5A1C /* Pods_CNLiveCMineModule_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 130B9380A777E212AEB45D18 /* Pods_CNLiveCMineModule_Tests.framework */; }; |
| 34 | 35 | /* End PBXBuildFile section */ |
| ... | ... | @@ -77,6 +78,8 @@ |
| 77 | 78 | 7900B454277BF103001CC115 /* CNLiveCMineViewModuleImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveCMineViewModuleImpl.h; sourceTree = "<group>"; }; |
| 78 | 79 | 7900B455277BF103001CC115 /* CNLiveCMineViewModuleImpl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveCMineViewModuleImpl.m; sourceTree = "<group>"; }; |
| 79 | 80 | 8098C304961155DEB9CF1284 /* Pods-CNLiveCMineModule_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CNLiveCMineModule_Tests.release.xcconfig"; path = "Target Support Files/Pods-CNLiveCMineModule_Tests/Pods-CNLiveCMineModule_Tests.release.xcconfig"; sourceTree = "<group>"; }; |
| 81 | + 815C179F2942FA93005EB1E6 /* CNPushSetupManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNPushSetupManager.h; sourceTree = "<group>"; }; | |
| 82 | + 815C17A02942FA94005EB1E6 /* CNPushSetupManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNPushSetupManager.m; sourceTree = "<group>"; }; | |
| 80 | 83 | 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; |
| 81 | 84 | 9D3FF658F60BFF2571211A3D /* CNLiveCMineModule.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = CNLiveCMineModule.podspec; path = ../CNLiveCMineModule.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; |
| 82 | 85 | A01134F0716FF93B67CCEC16 /* Pods-CNLiveCMineModule_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CNLiveCMineModule_Example.debug.xcconfig"; path = "Target Support Files/Pods-CNLiveCMineModule_Example/Pods-CNLiveCMineModule_Example.debug.xcconfig"; sourceTree = "<group>"; }; |
| ... | ... | @@ -148,6 +151,8 @@ |
| 148 | 151 | 6003F593195388D20070C39A /* Example for CNLiveCMineModule */ = { |
| 149 | 152 | isa = PBXGroup; |
| 150 | 153 | children = ( |
| 154 | + 815C179F2942FA93005EB1E6 /* CNPushSetupManager.h */, | |
| 155 | + 815C17A02942FA94005EB1E6 /* CNPushSetupManager.m */, | |
| 151 | 156 | 6003F59C195388D20070C39A /* CNLIVEAppDelegate.h */, |
| 152 | 157 | 6003F59D195388D20070C39A /* CNLIVEAppDelegate.m */, |
| 153 | 158 | 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */, |
| ... | ... | @@ -411,6 +416,7 @@ |
| 411 | 416 | isa = PBXSourcesBuildPhase; |
| 412 | 417 | buildActionMask = 2147483647; |
| 413 | 418 | files = ( |
| 419 | + 815C17A12942FA94005EB1E6 /* CNPushSetupManager.m in Sources */, | |
| 414 | 420 | 6003F59E195388D20070C39A /* CNLIVEAppDelegate.m in Sources */, |
| 415 | 421 | 6003F5A7195388D20070C39A /* CNLIVEViewController.m in Sources */, |
| 416 | 422 | 08B0D70027950568004125CE /* CNCollectionViewCell.m in Sources */, | ... | ... |
Example/CNLiveCMineModule/CNLiveCMineViewModuleImpl.m
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | #import <CNLiveUserManagement/CNUserInfoManager.h> |
| 11 | 11 | //CNLiveSDK |
| 12 | 12 | #import <CNLiveUserSystemSDK/CNLiveUserSystemCenter.h> |
| 13 | +#import "CNPushSetupManager.h" | |
| 13 | 14 | @implementation CNLiveCMineViewModuleImpl |
| 14 | 15 | #define CNUserShareModel CNUserShareManager.userInfoModel |
| 15 | 16 | |
| ... | ... | @@ -166,4 +167,11 @@ |
| 166 | 167 | - (NSString *)base64StringDecrypt:(NSString *)str encryptKey:(NSString *)encryptKey{ |
| 167 | 168 | return str; |
| 168 | 169 | } |
| 170 | +/// 更新推送设置 | |
| 171 | +/// @param on yes:关闭推送 No:打开推送 | |
| 172 | +/// @param userId 会话id | |
| 173 | +/// @param complete 请求完成回调 | |
| 174 | +- (void)updateSetupStatus:(BOOL)on userId:(NSString *)userId block:(void (^)(BOOL succ))complete{ | |
| 175 | + [CNPushSetupManager updateSetupStatus:on userId:userId block:complete]; | |
| 176 | +} | |
| 169 | 177 | @end | ... | ... |
Example/CNLiveCMineModule/CNPushSetupManager.h
0 → 100644
| 1 | +// | |
| 2 | +// CNPushSetupManager.h | |
| 3 | +// CNLiveNetAdd | |
| 4 | +// | |
| 5 | +// Created by daojian on 2021/3/3. | |
| 6 | +// Copyright © 2021 cnlive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <Foundation/Foundation.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | + | |
| 13 | +/// 直播号,新闻号,请求一刻 推送管理类 | |
| 14 | +@interface CNPushSetupManager : NSObject | |
| 15 | + | |
| 16 | +/// 更新推送设置 | |
| 17 | +/// @param on yes:关闭推送 No:打开推送 | |
| 18 | +/// @param userId 会话id | |
| 19 | +/// @param complete 请求完成回调 | |
| 20 | ++ (void)updateSetupStatus:(BOOL)on userId:(NSString *)userId block:(void (^)(BOOL succ))complete; | |
| 21 | + | |
| 22 | +@end | |
| 23 | + | |
| 24 | +NS_ASSUME_NONNULL_END | ... | ... |
Example/CNLiveCMineModule/CNPushSetupManager.m
0 → 100644
| 1 | +// | |
| 2 | +// CNPushSetupManager.m | |
| 3 | +// CNLiveNetAdd | |
| 4 | +// | |
| 5 | +// Created by daojian on 2021/3/3. | |
| 6 | +// Copyright © 2021 cnlive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNPushSetupManager.h" | |
| 10 | +#import <CNLiveEnvironment/CNLiveEnvironment.h> | |
| 11 | +#import <CNLiveUserManagement/CNUserInfoManager.h> | |
| 12 | +#import <QMUIKit/QMUIKit.h> | |
| 13 | +#import <CNLiveNetworking.h> | |
| 14 | +#import <CNLiveBaseKit/CNLiveBaseKit.h> | |
| 15 | + | |
| 16 | +//新闻号 | |
| 17 | +static NSString *const CNWithNews = @"sys_news"; | |
| 18 | +//直播号 | |
| 19 | +static NSString *const CNWithLive = @"sys_live"; | |
| 20 | +//视频号 | |
| 21 | +static NSString *const CNWithVideo = @"sys_video"; | |
| 22 | +//直播号是否设置消息免打扰 0:没有 1:有 | |
| 23 | +static NSString *const CNWithLiveReceiveMessageOpt = @"CNWithLiveReceiveMessageOpt"; | |
| 24 | + | |
| 25 | +//新闻号是否设置消息免打扰 0:没有 1:有 | |
| 26 | +static NSString *const CNWithNewsReceiveMessageOpt = @"CNWithNewsReceiveMessageOpt"; | |
| 27 | + | |
| 28 | +//轻松一刻号是否设置消息免打扰 0:没有 1:有 | |
| 29 | +static NSString *const CNWithVideoReceiveMessageOpt = @"CNWithVideoReceiveMessageOpt"; | |
| 30 | + | |
| 31 | +@implementation CNPushSetupManager | |
| 32 | + | |
| 33 | +/// 更新推送设置 | |
| 34 | ++ (void)updateSetupStatus:(BOOL)on userId:(NSString *)userId block:(void (^)(BOOL succ))complete | |
| 35 | +{ | |
| 36 | + NSString *url = [NSString stringWithFormat:@"%@/Daren/news/shieldingMsg.action",API_Host]; | |
| 37 | + NSMutableDictionary *params = [NSMutableDictionary new]; | |
| 38 | + [params setObject:CNUserShareModelUid forKey:@"sid"]; | |
| 39 | + [params setObject:[NSString stringWithFormat:@"%d",on] forKey:@"switchs"]; | |
| 40 | + [params setObject:userId forKey:@"type"]; | |
| 41 | + [QMUITips showLoadingInView:AppKeyWindow]; | |
| 42 | + [CNLiveNetworking setupShowDataResult:NO]; | |
| 43 | + [CNLiveNetworking setAllowRequestDefaultArgument:YES]; | |
| 44 | + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:url Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, NSDictionary *responseObject, NSError *error) { | |
| 45 | + | |
| 46 | + [QMUITips hideAllTipsInView:AppKeyWindow]; | |
| 47 | + | |
| 48 | + if (!error) { | |
| 49 | + NSString *errorCode = [NSString stringWithFormat:@"%@",responseObject[@"errorCode"]]; | |
| 50 | + if ([errorCode isEqualToString:@"0"]) { | |
| 51 | + [QMUITips showSucceed:@"设置成功"]; | |
| 52 | + if (on) { | |
| 53 | + if ([userId isEqualToString:CNWithNews]) { | |
| 54 | + [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:CNWithNewsReceiveMessageOpt]; | |
| 55 | + } | |
| 56 | + else if ([userId isEqualToString:CNWithLive]) | |
| 57 | + { | |
| 58 | + [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:CNWithLiveReceiveMessageOpt]; | |
| 59 | + } | |
| 60 | + else if ([userId isEqualToString:@"sys_video"]) | |
| 61 | + { | |
| 62 | + [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:CNWithVideoReceiveMessageOpt]; | |
| 63 | + } | |
| 64 | + } | |
| 65 | + else | |
| 66 | + { | |
| 67 | + if ([userId isEqualToString:CNWithNews]) | |
| 68 | + { | |
| 69 | + [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:CNWithNewsReceiveMessageOpt]; | |
| 70 | + } | |
| 71 | + else if ([userId isEqualToString:CNWithLive]) | |
| 72 | + { | |
| 73 | + [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:CNWithLiveReceiveMessageOpt]; | |
| 74 | + } | |
| 75 | + else if ([userId isEqualToString:@"sys_video"]) | |
| 76 | + { | |
| 77 | + [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:CNWithVideoReceiveMessageOpt]; | |
| 78 | + } | |
| 79 | + } | |
| 80 | + if(complete)complete(YES); | |
| 81 | + } | |
| 82 | + else | |
| 83 | + { | |
| 84 | + [QMUITips showError:responseObject[@"errorMessage"]]; | |
| 85 | + if(complete)complete(NO); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + else | |
| 89 | + { | |
| 90 | + [QMUITips showError:error.domain]; | |
| 91 | + if(complete)complete(NO); | |
| 92 | + } | |
| 93 | + }]; | |
| 94 | +} | |
| 95 | +@end | ... | ... |