// // YMMineNotificaViewController.m // YUMI // // Created by YUMI on 2021/9/17. // #import "XPMineNotificaViewController.h" ///Third #import #import ///Tool #import "DJDKMIMOMColor.h" #import "YUMIMacroUitls.h" #import "NSArray+Safe.h" ///Model #import "XPMineNotificationItemModel.h" ///View #import "XPMineNotificationTableViewCell.h" ///P #import "XPMineNotificaProtocol.h" #import "XPMineNotificaPresenter.h" @interface XPMineNotificaViewController () @property (nonatomic, strong) NSArray *dataModelArray; /// @property (nonatomic,strong) UITableView *tableView; @end @implementation XPMineNotificaViewController - (XPMineNotificaPresenter *)createPresenter { return [[XPMineNotificaPresenter alloc] init]; } #pragma mark - Life Cycle - (void)viewDidLoad { [super viewDidLoad]; [self initSubViews]; [self initSubViewConstraints]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.presenter requestUserInfoNotifyStatus]; } #pragma mark - Private Method - (void)initSubViews { self.title = YMLocalizedString(@"XPMineNotificaViewController0"); [self.view addSubview:self.tableView]; } - (void)initSubViewConstraints { [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.bottom.mas_equalTo(self.view); make.top.mas_equalTo(0); }]; } /// 获取系统通知权限 - (BOOL)systemNotify { #warning to do 需要实现的 /* SecretarySystemUIDs *uids = GetCore(ImFriendCore).secretarySystemUIDs; if (uids == nil) { //uid为空时,获取、缓存 [GetCore(ImFriendCore) requestSecretarySystemUIDsWithCompletion:nil]; return NO; } BOOL secretaryNotify = [GetCore(ImFriendCore) notifyForNewMsg:uids.secretaryUid]; BOOL systemNotify = [GetCore(ImFriendCore) notifyForNewMsg:uids.systemMessageUid]; return secretaryNotify && systemNotify; */ return YES; } #pragma mark - UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataModelArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { XPMineNotificationItemModel *item = [self.dataModelArray xpSafeObjectAtIndex:indexPath.row]; XPMineNotificationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineNotificationTableViewCell class]) forIndexPath:indexPath]; cell.delegate = self; cell.itemModel = item; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 80; } #pragma mark - Private /// 获取手机推送权限 + (void)mobilePushAuthority:(void(^)(BOOL isAuthority))authority { if (@available(iOS 10.0, *)) { [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { BOOL permission = settings.authorizationStatus == UNAuthorizationStatusAuthorized; dispatch_async(dispatch_get_main_queue(), ^{ !authority ?: authority(permission); }); }]; } else { BOOL permission = [[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone; !authority ?: authority(permission); } } #pragma mark - XPMineNotificationTableViewCell - (void)xPMineNotificationTableViewCell:(XPMineNotificationTableViewCell *)cell switchStatus:(BOOL)status { NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; self.dataModelArray[indexPath.row].notification = status; if (indexPath.row == 0) { [self.presenter updateUserInfoSystemNotify:status]; } else { [self.presenter updateBroadCastNotify:status]; } /* if (!status) { #warning to do 弹框 // [TTPopup alertWithMessage:@"您未开启推送通知权限,请前往设置" confirmHandler:^{ // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; // } cancelHandler:^{ // // }]; self.dataModelArray[0].notification = NO; [self.tableView reloadData]; return; } //iOS端只上传给服务器统计,暂无业务操作关系 [self.presenter updateUserInfoSystemNotify:status]; */ } #pragma mark - XPMineNotificaProtocol - (void)requestUserInfoNotifyStatusSuccess:(NSArray *)array { self.dataModelArray = array; [self.tableView reloadData]; } - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [_tableView registerClass:[XPMineNotificationTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineNotificationTableViewCell class])]; _tableView.backgroundColor = [UIColor clearColor]; } return _tableView; } @end