From 5c96cc41666882037146cc9019bd2c8c0ac61365 Mon Sep 17 00:00:00 2001 From: coderZsq Date: Sun, 29 Sep 2019 21:17:17 +0800 Subject: [PATCH] add --- .../SQConnectionEventsViewController.m | 21 ++++++++++++++++--- .../Connections/SQConnectionModel.h | 1 + .../Connections/SQConnectionModel.m | 13 ++++++++++++ .../Connections/SQConnectionsViewController.m | 3 ++- .../SQManagement/Tools/SQAuthorizationTool.m | 20 ++++++++++++++---- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/SQManagement/SQManagement/Connections/SQConnectionEventsViewController.m b/SQManagement/SQManagement/Connections/SQConnectionEventsViewController.m index 5c0c8222..9b033d1f 100644 --- a/SQManagement/SQManagement/Connections/SQConnectionEventsViewController.m +++ b/SQManagement/SQManagement/Connections/SQConnectionEventsViewController.m @@ -36,6 +36,7 @@ - (void)viewDidLoad { self.tableView.backgroundColor = [UIColor colorWithHexString:@"f8f8f8"]; [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([SQConnectionPropertyCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([SQConnectionPropertyCell class])]; self.headerView = [SQProfileHeaderView headerView]; + self.headerView.profileImageView.image = [UIImage imageWithData:self.connection.profile];; __weak typeof(self) weakSelf = self; [self.headerView whenTapped:^{ UIImagePickerController *imagePickerVc = [[UIImagePickerController alloc] init]; @@ -91,9 +92,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - if (indexPath.section == 0) { - UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"请输入 - %@", self.dataSource[indexPath.section][indexPath.row]] preferredStyle:(UIAlertControllerStyleAlert)]; - [alertVc addTextFieldWithConfigurationHandler:nil]; + if (indexPath.section == 0 && indexPath.row < 5) { + NSString *string = self.dataSource[indexPath.section][indexPath.row]; + UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:string preferredStyle:(UIAlertControllerStyleAlert)]; + [alertVc addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { + textField.text = [self mapConnectionModelFor:string]; + textField.placeholder = [NSString stringWithFormat:@"请输入%@", string]; + }]; [alertVc addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil]]; __weak typeof(alertVc) weakSelf = alertVc; [alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { @@ -104,6 +109,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath } } +- (NSString *)mapConnectionModelFor:(NSString *)key { + return @{ + @"姓名" : self.connection.name, + @"角色" : self.connection.role, + @"职业" : self.connection.occupation, + @"地区" : self.connection.region, + @"行业" : self.connection.industry + }[key]; +} + - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:nil]; self.headerView.profileImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; diff --git a/SQManagement/SQManagement/Connections/SQConnectionModel.h b/SQManagement/SQManagement/Connections/SQConnectionModel.h index d2dab00b..7e771699 100644 --- a/SQManagement/SQManagement/Connections/SQConnectionModel.h +++ b/SQManagement/SQManagement/Connections/SQConnectionModel.h @@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SQConnectionModel : NSObject @property (nonatomic, strong) NSData *profile; +@property (nonatomic, copy) NSString *identifier; @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *role; @property (nonatomic, copy) NSString *occupation; diff --git a/SQManagement/SQManagement/Connections/SQConnectionModel.m b/SQManagement/SQManagement/Connections/SQConnectionModel.m index 696b3a1a..6e200b6e 100644 --- a/SQManagement/SQManagement/Connections/SQConnectionModel.m +++ b/SQManagement/SQManagement/Connections/SQConnectionModel.m @@ -22,6 +22,19 @@ typedef NS_ENUM(NSInteger, SQConnectionProperty) { @implementation SQConnectionModel +- (instancetype)init +{ + self = [super init]; + if (self) { + self.name = @""; + self.role = @""; + self.occupation= @""; + self.region = @""; + self.industry = @""; + } + return self; +} + - (void)map:(NSUInteger)row bind:(UIView *)view { switch (row) { case SQConnectionName: diff --git a/SQManagement/SQManagement/Connections/SQConnectionsViewController.m b/SQManagement/SQManagement/Connections/SQConnectionsViewController.m index 6932773b..d4b18024 100644 --- a/SQManagement/SQManagement/Connections/SQConnectionsViewController.m +++ b/SQManagement/SQManagement/Connections/SQConnectionsViewController.m @@ -26,7 +26,8 @@ - (void)viewDidLoad { [SQAuthorizationTool fetchContacts:^(NSArray * _Nonnull contacts) { for (SQContact *contact in contacts) { SQConnectionModel *model = [SQConnectionModel new]; - model.profile = contact.imageData; + model.identifier = contact.identifier; + model.profile = contact.thumbnailImageData; model.name = [NSString stringWithFormat:@"%@%@", contact.familyName, contact.givenName]; model.occupation = contact.jobTitle; [self.dataSource addObject:model]; diff --git a/SQManagement/SQManagement/Tools/SQAuthorizationTool.m b/SQManagement/SQManagement/Tools/SQAuthorizationTool.m index 9edf68ec..af04d440 100644 --- a/SQManagement/SQManagement/Tools/SQAuthorizationTool.m +++ b/SQManagement/SQManagement/Tools/SQAuthorizationTool.m @@ -115,10 +115,22 @@ + (void)fetchContacts:(void (^)(NSArray * _Nonnull))callback{ [dates addObject:[NSString stringWithFormat:@"%@: %@", label, [dateFormatter stringFromDate:value]]]; } obj.dates = dates; -// obj.urlAddresses = contact.urlAddresses; -// obj.contactRelations = contact.contactRelations; -// obj.socialProfiles = contact.socialProfiles; -// obj.instantMessageAddresses = contact.instantMessageAddresses; + NSMutableArray *urlAddresses = @[].mutableCopy; + for (CNLabeledValue *urlAddress in contact.urlAddresses) { + [urlAddresses addObject:[CNLabeledValue localizedStringForLabel:urlAddress.label]]; + } + obj.urlAddresses = urlAddresses; + NSMutableArray *socialProfiles = @[].mutableCopy; + for (CNLabeledValue *socialProfile in contact.socialProfiles) { + [urlAddresses addObject:[CNLabeledValue localizedStringForLabel:socialProfile.label]]; + } + obj.socialProfiles = socialProfiles; + NSMutableArray *instantMessageAddresses = @[].mutableCopy; + for (CNLabeledValue *instantMessageAddress in contact.instantMessageAddresses) { + [instantMessageAddresses addObject:[CNLabeledValue localizedStringForLabel:instantMessageAddress.label]]; + } + obj.socialProfiles = socialProfiles; + obj.instantMessageAddresses = instantMessageAddresses; [array addObject:obj]; }]; if (callback) {