Commit bbf83af7 authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

1.delete contacts

2.payVC   config
parent ecb1d7e4
......@@ -700,21 +700,16 @@
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="¥68.00/周" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="L7v-8r-0y1">
<rect key="frame" x="129" y="19.5" width="87" height="21.5"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="18"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="textColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="0.5" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" red="0.89411764705882346" green="0.89411764705882346" blue="0.89411764705882346" alpha="0.5" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="L7v-8r-0y1" firstAttribute="centerY" secondItem="DBF-4w-bui" secondAttribute="centerY" id="Pue-Ll-1BC"/>
<constraint firstAttribute="width" secondItem="DBF-4w-bui" secondAttribute="height" multiplier="345:60" id="fpZ-qy-Ynl"/>
<constraint firstItem="L7v-8r-0y1" firstAttribute="centerX" secondItem="DBF-4w-bui" secondAttribute="centerX" id="isf-lQ-3gq"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="massBackgroundColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XCc-gG-Ht4">
<rect key="frame" x="20" y="577.5" width="58" height="29"/>
......@@ -803,8 +798,8 @@
</stackView>
</subviews>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="3天免费试用,之后" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="eov-CU-eqn">
<rect key="frame" x="108.5" y="381" width="158" height="21.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="3天免费试用,之后" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="eov-CU-eqn">
<rect key="frame" x="10" y="381" width="355" height="21.5"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" red="0.20392156862745098" green="0.20392156862745098" blue="0.20392156862745098" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
......@@ -856,6 +851,7 @@
<constraint firstItem="tQ9-Em-wwg" firstAttribute="leading" secondItem="DBF-4w-bui" secondAttribute="leading" id="Afz-II-rHE"/>
<constraint firstItem="ZWf-bI-o2B" firstAttribute="trailing" secondItem="0lR-Zv-zNp" secondAttribute="trailing" constant="15" id="C1M-BK-ka4"/>
<constraint firstItem="iWV-sR-CmX" firstAttribute="top" secondItem="ZWf-bI-o2B" secondAttribute="top" constant="20" id="JRw-0O-hAL"/>
<constraint firstItem="eov-CU-eqn" firstAttribute="leading" secondItem="ZWf-bI-o2B" secondAttribute="leading" constant="10" id="Rux-cP-mM2"/>
<constraint firstItem="eov-CU-eqn" firstAttribute="centerX" secondItem="hz3-9J-l4v" secondAttribute="centerX" id="St3-3Y-BIn"/>
<constraint firstItem="XCc-gG-Ht4" firstAttribute="leading" secondItem="DBF-4w-bui" secondAttribute="leading" constant="5" id="UG6-V7-o73"/>
<constraint firstItem="LJM-xO-Pur" firstAttribute="trailing" secondItem="zhb-eK-mF2" secondAttribute="trailing" id="URe-AS-wu8"/>
......
......@@ -78,7 +78,18 @@
if ([model.productId containsString:@"week"]) {
weakSelf.weakPeriodOfUseLabel.text = model.name;
} else if ([model.productId containsString:@"year"]) {
weakSelf.yearPeriodOfUseLabel.text = model.name;
// weakSelf.yearPeriodOfUseLabel.text = model.name;
weakSelf.yearPeriodOfUseLabel.text = @"开始免费试用";
self.weakPriceLabel.text = [NSString stringWithFormat:@"3天免费试用,之后 %@", model.name];
Data * data = [[Data alloc] init];
NSDictionary * dic = [[data Read] objectForKey:@"config"];
if (dic) {
self.weakPriceLabel.text = [NSString stringWithFormat:@"%@ %@", [dic objectForKey:@"pay_3day_txt"], model.name];
weakSelf.yearPeriodOfUseLabel.text = [dic objectForKey:@"478_button_text"];
}
}
}
}
......
//
// ICContactListModel.h
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactListModel : NSObject
@property(nonatomic,strong)CNContact *contact;
@property(nonatomic,assign)BOOL choose;
@end
NS_ASSUME_NONNULL_END
//
// ICContactListModel.m
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactListModel.h"
@implementation ICContactListModel
@end
//
// ICContactsBackup.h
// superCleaner
//
// Created by GY.Z on 2020/7/7.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactsBackup : NSObject
@property(nonatomic,copy)NSString *kMDItemContentType;
@property(nonatomic,copy)NSString *kMDItemFSContentChangeDate;
@property(nonatomic,copy)NSString *kMDItemFSName;
@property(nonatomic,copy)NSURL *kMDItemURL;
@property(nonatomic,copy)NSString *kMDItemFSSize;
@property(nonatomic,copy)NSString *timestamp;
@property(nonatomic,assign)BOOL choose;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsBackup.m
// superCleaner
//
// Created by GY.Z on 2020/7/7.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsBackup.h"
@implementation ICContactsBackup
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
@end
//
// ICContactsTool.h
// superCleaner
//
// Created by GY.Z on 2020/7/6.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@protocol ICContactsToolDelegate <NSObject>
// 获取iCloud联系人
-(void)getiCloudContactsMethods:(NSData *)obj fileInfo:(NSDictionary *)fileInfo;
/// 获取iCloud列表
-(void)getiCloudList:(NSArray *)lists;
@end
@interface ICContactsTool : NSObject
@property(nonatomic,weak)id <ICContactsToolDelegate> delegate;
+(instancetype)shareInstance;
// 获取联系人
-(NSArray *)fetchContacts;
// 获取联系人授权状态
-(BOOL)contactsAuthStatus;
// 删除联系人
- (void)deleteContact:(CNMutableContact *)contact;
// 更新联系人
- (void)updateContact:(CNMutableContact *)contact;
// 获取iCloud容器联系人
-(void)getiCloudContactsPath:(NSURL *)path;
/// 获取联系人列表
-(void)loadiCloudDirectory;
/// 备份联系人
-(void)synciCloudContactsFileName:(NSString *)fileName;
/// 删除备份
-(void)deleteiCloudContactsUrlFile:(NSURL *)urlFile;
// 获取日期天
-(NSInteger)getCurrentDay;
-(NSString *)convertStrToTime:(NSString *)timeStr;
/// 获取时间戳
-(NSString *)getNowTimeTimestamp;
/// 设置删除和合并次数
-(void)registerDeleteOrMergeCount;
/// 重置删除和合并次数
-(void)resetCount;
/// 联系人详情note信息
@property(nonatomic,copy)NSString *note;
/// 进入联系人详情
-(void)enterContactsDetail:(CNContact *)contact controller:(UIViewController *)controller push:(BOOL)push;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsTool.m
// superCleaner
//
// Created by GY.Z on 2020/7/6.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsTool.h"
#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
#import "PYHDocument.h"
#import <objc/runtime.h>
#define UbiquityContainerIdentifiers @"iCloud.com.app.superCleanMaster"
@interface ICContactsTool ()<PYHDocumentDelegate>
{
NSMetadataQuery *_metaQuery;
}
@property(nonatomic,strong)NSArray *keys;
@property(nonatomic,strong)UIViewController *contactController;
@property(nonatomic,assign)BOOL contactPush;
@end
static ICContactsTool *tool = nil;
@implementation ICContactsTool
+(instancetype)shareInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
tool = [[ICContactsTool alloc] init];
});
return tool;
}
-(BOOL)contactsAuthStatus
{
BOOL isAvalible = NO;
CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
switch (authStatus) {
case CNAuthorizationStatusAuthorized:
isAvalible = YES;
break;
case CNAuthorizationStatusDenied:
{
[MBProgressHUD showMessage:ICLocalized(@"AddressBookOpen")];
isAvalible = NO;
}
break;
case CNAuthorizationStatusNotDetermined:
{
isAvalible = YES;
}
break;
case CNAuthorizationStatusRestricted:
[MBProgressHUD showMessage: ICLocalized(@"AddressBookOpen")];
isAvalible = NO;
break;
}
return isAvalible;
}
-(void)synciCloudContactsFileName:(NSString *)fileName
{
NSArray *contacts = [self fetchContacts];
[self saveiCloud:contacts fileName:fileName];
}
-(void)loadiCloudDirectory
{
[_metaQuery stopQuery];
_metaQuery = nil;
_metaQuery = [[NSMetadataQuery alloc]init];
_metaQuery.searchScopes = @[NSMetadataQueryUbiquitousDataScope];
_metaQuery.notificationBatchingInterval = 15;
NSOperationQueue *queue = [NSOperationQueue mainQueue];
_metaQuery.operationQueue = queue;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gatherFinish:) name:NSMetadataQueryDidFinishGatheringNotification object:_metaQuery];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gatherFinish:) name:NSMetadataQueryDidUpdateNotification object:_metaQuery];
[_metaQuery startQuery];
}
-(void)gatherFinish:(NSNotification*)nofification
{
NSMetadataQuery *query = nofification.object;
[query disableUpdates];
NSLog(@"------resultCount:%lu",(unsigned long)query.resultCount);
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:query];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidUpdateNotification object:query];
if (query.resultCount > 0) {
NSArray *result = query.results;
NSMutableArray *datasource = [NSMutableArray array];
for (NSMetadataItem *item in result) {
NSDictionary *dic = [item valuesForAttributes:@[NSMetadataItemFSSizeKey,NSMetadataItemFSNameKey,NSMetadataItemURLKey,NSMetadataItemFSContentChangeDateKey,NSMetadataItemContentTypeKey]];
[datasource addObject:dic];
// NSLog(@"%@",item.attributes);
}
NSLog(@"datasource = %@",datasource);
NSMutableArray *temp = [[NSMutableArray alloc] init];
NSMutableArray *lastArr = [[NSMutableArray alloc] init];
NSMutableArray *source = [[NSMutableArray alloc] init];
for (NSDictionary *dict in datasource) {
if (dict[@"kMDItemFSName"] && [dict[@"kMDItemFSName"] containsString:@"Contacts-"]) {
[temp addObject:dict];
}else{
[lastArr addObject:dict];
}
}
for (NSDictionary *dict in temp) {
NSString *name = dict[@"kMDItemFSName"];
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic addEntriesFromDictionary:dict];
for (NSDictionary *dict in lastArr) {
NSString *kMDItemFSName = dict[@"kMDItemFSName"];
if ([name containsString:kMDItemFSName]) {
dic[@"kMDItemFSSize"] = dict[@"kMDItemFSSize"] ? dict[@"kMDItemFSSize"] : @"0";
[source addObject:dic];
continue;
}
}
}
if (self.delegate && [self.delegate respondsToSelector:@selector(getiCloudList:)]) {
[self.delegate getiCloudList:source];
}
}
[query enableUpdates];
}
-(void)saveiCloud:(NSArray *)contacts fileName:(NSString *)fileName
{
NSURL *ubiquityURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:UbiquityContainerIdentifiers];
//验证iCloud是否可用
if(!ubiquityURL)
{
[MBProgressHUD showMessage: ICLocalized(@"ICloudIsNotEnabled")];
return;
}
if (contacts.count == 0)
{
[MBProgressHUD showMessage: ICLocalized(@"EmptyContact")];
return;
}
[MBProgressHUD showLoading: ICLocalized(@"BackingUp")];
NSURL *myContainer = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:NSMetadataQueryUbiquitousDataScope];
if (myContainer != nil) {
NSLog(@"应用可以写入iCloud容器,iCloud容器地址:%@",myContainer);
NSURL *cloudUrl = [myContainer URLByAppendingPathComponent:[NSString stringWithFormat:@"Contacts-%@",fileName]];
// NSURL *cloudUrl = [myContainer URLByAppendingPathComponent:@"contacts"];
NSLog(@"cloudUrl = %@",cloudUrl);
PYHDocument *document = [[PYHDocument alloc]initWithFileURL:cloudUrl];
//要保存的数据
document.saveData = [NSKeyedArchiver archivedDataWithRootObject:contacts];;
document.saveFileName = fileName;
[document saveToURL:document.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
if (success) {
[MBProgressHUD showSuccess: ICLocalized(@"BackupCompleted")];
}else{
[MBProgressHUD showError: ICLocalized(@"BackupFailedPleaseTryAgain")];
}
[document closeWithCompletionHandler:^(BOOL success) {
}];
}];
}
}
-(void)deleteiCloudContactsUrlFile:(NSURL *)urlFile
{
BOOL flag = [[NSFileManager defaultManager] removeItemAtURL:urlFile error:nil];
if (flag) {
NSLog(@"删除成功:urlFile = %@",urlFile.absoluteString);
}else{
NSLog(@"删除失败:urlFile = %@",urlFile.absoluteString);
}
}
-(void)getiCloudContactsPath:(NSURL *)path
{
PYHDocument *document = [[PYHDocument alloc] initWithFileURL:path];
document.delegate = self;
// 打开
[document openWithCompletionHandler:^(BOOL success) {
if (success) {
[MBProgressHUD showSuccess: ICLocalized(@"OpenSuccess")];
}else{
[MBProgressHUD showError: ICLocalized(@"FailedOpenTryLater")];
}
// 关闭
[document closeWithCompletionHandler:^(BOOL success) {
}];
}];
}
-(void)docGetiCloudContactsMethods:(NSData *)obj fileInfo:(nonnull NSDictionary *)fileInfo
{
if (self.delegate && [self.delegate respondsToSelector:@selector(getiCloudContactsMethods:fileInfo:)]) {
[self.delegate getiCloudContactsMethods:obj fileInfo:fileInfo];
}
}
-(NSArray *)fetchContacts{
CNContactStore *store = [[CNContactStore alloc] init];
CNContactFetchRequest *fetchRequest = [[CNContactFetchRequest alloc] initWithKeysToFetch: [self keys]];
NSMutableArray *contacts = [NSMutableArray array];
[store enumerateContactsWithFetchRequest:fetchRequest error:nil usingBlock:^(CNContact * _Nonnull contact, BOOL * _Nonnull stop) {
[contacts addObject:contact];
}];
return contacts;
}
// 删除联系人
- (void)deleteContact:(CNMutableContact *)contact{
// 创建联系人请求
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest deleteContact:contact];
// 写入操作
CNContactStore *store = [[CNContactStore alloc] init];
[store executeSaveRequest:saveRequest error:nil];
}
// 更新联系人
- (void)updateContact:(CNMutableContact *)contact{
// 创建联系人请求
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
[saveRequest updateContact:contact];
// 重新写入
CNContactStore *store = [[CNContactStore alloc] init];
[store executeSaveRequest:saveRequest error:nil];
}
-(void)archive
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentFilePath = paths.firstObject;
NSString *filePath = [documentFilePath stringByAppendingPathComponent:@"fetchContacts"];
CNMutableContact *contact = [[CNMutableContact alloc] init];
contact.givenName = @"san";
contact.familyName = @"wangg";
[NSKeyedArchiver archiveRootObject:contact toFile:filePath];
}
-(void)unarchive
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentFilePath = paths.firstObject;
NSString *filePath = [documentFilePath stringByAppendingPathComponent:@"fetchContacts"];
CNMutableContact *p1 = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath] ;
NSLog(@"%@", p1.familyName);
NSLog(@"%@", p1.givenName);
}
- (NSArray *)keys
{
if (!_keys) {
_keys = @[[CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName],
CNContactPhoneNumbersKey,
CNContactOrganizationNameKey,
CNContactDepartmentNameKey,
CNContactJobTitleKey,
CNContactPhoneticGivenNameKey,
CNContactPhoneticFamilyNameKey,
CNContactPhoneticMiddleNameKey,
CNContactImageDataKey,
CNContactThumbnailImageDataKey,
CNContactEmailAddressesKey,
CNContactPostalAddressesKey,
CNContactBirthdayKey,
CNContactNonGregorianBirthdayKey,
CNContactInstantMessageAddressesKey,
CNContactSocialProfilesKey,
CNContactRelationsKey,
CNContactUrlAddressesKey,
CNContactViewController.descriptorForRequiredKeys];
}
return _keys;
}
-(NSInteger)getCurrentDay
{
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//获取当前时间日期展示字符串 如:2019-05-23-13:58:59
// NSString *str = [formatter stringFromDate:date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [[NSDateComponents alloc] init];
// NSInteger unitFlags = NSCalendarUnitYear |NSCalendarUnitMonth |NSCalendarUnitDay |NSCalendarUnitWeekday |NSCalendarUnitHour |NSCalendarUnitMinute |NSCalendarUnitSecond;
comps = [calendar components:NSCalendarUnitDay fromDate:date];
NSInteger day = [comps day];
return day;
}
-(NSString *)getNowTimeTimestamp{
NSDate *datenow = [NSDate date];
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
return timeSp;
}
//时间戳变为格式时间
- (NSString *)convertStrToTime:(NSString *)timeStr
{
long long time=[timeStr longLongValue];
NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *timeString=[formatter stringFromDate:date];
return timeString;
// NSString* timeStr = @"2020-07-08 03:45:31";
// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
// [formatter setDateStyle:NSDateFormatterMediumStyle];
// [formatter setTimeStyle:NSDateFormatterShortStyle];
// [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
//
// //设置时区,这个对于时间的处理有时很重要
// //例如你在国内发布信息,用户在国外的另一个时区,你想让用户看到正确的发布时间就得注意时区设置,时间的换算.
// //例如你发布的时间为2010-01-26 17:40:50,那么在英国爱尔兰那边用户看到的时间应该是多少呢?
// //他们与我们有7个小时的时差,所以他们那还没到这个时间呢...那就是把未来的事做了1550738762
//
// NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
// [formatter setTimeZone:timeZone];
// NSDate* date = [formatter dateFromString:timeStr]; //------------将字符串按formatter转成nsdate
// NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
// NSString *nowtimeStr = [formatter stringFromDate:datenow];//----------将nsdate按formatter格式转成
//
// //时间转时间戳的方法:
// NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
// NSLog(@"timeSp:%@",timeSp); //时间戳的值
}
-(void)registerDeleteOrMergeCount
{
NSString *key = [NSString stringWithFormat:@"%ld",(long)[[ICContactsTool shareInstance] getCurrentDay]];
NSUbiquitousKeyValueStore *keyValueStore = [NSUbiquitousKeyValueStore defaultStore];
NSString *count = [keyValueStore objectForKey:[NSString stringWithFormat:@"delete_%@",key]];
if (count.length == 0) {
// 设置不完整联系人删除次数
[keyValueStore setObject:@"5" forKey:[NSString stringWithFormat:@"delete_%@",key]];
// 设置合并联系人次数
[keyValueStore setObject:@"5" forKey:[NSString stringWithFormat:@"merge_%@",key]];
[keyValueStore synchronize];
}
}
-(void)resetCount
{
NSString *key = [NSString stringWithFormat:@"%ld",(long)[[ICContactsTool shareInstance] getCurrentDay]];
NSUbiquitousKeyValueStore *keyValueStore = [NSUbiquitousKeyValueStore defaultStore];
[keyValueStore removeObjectForKey:[NSString stringWithFormat:@"delete_%@",key]];
[keyValueStore removeObjectForKey:[NSString stringWithFormat:@"merge_%@",key]];
[keyValueStore synchronize];
}
-(void)enterContactsDetail:(CNContact *)contact controller:(nonnull UIViewController *)controller push:(BOOL)push
{
self.contactController = controller;
self.contactPush = push;
//1.创建Contact对象,必须是可变的
CNContactViewController *contactController = [CNContactViewController viewControllerForContact:contact.mutableCopy];
/// 是否显示打电话、发短信等按钮
contactController.allowsActions = YES;
/// 能否修改数据
contactController.allowsEditing = YES;
/// 是否显示联系人的关联联系人
contactController.shouldShowLinkedContacts = YES;
if (self.note.length) {
unsigned int count = 0;
Ivar *members = class_copyIvarList([CNContact class], &count);
for (int i = 0; i < count; i++) {
Ivar var = members[i];
const char *memberName = ivar_getName(var);
NSString *str = [NSString stringWithUTF8String:memberName];
if ([str isEqualToString:@"_note"]) {
// Ivar var = class_getInstanceVariable([CNContact class], "_note");
object_setIvar(contactController.contact, var, self.note);
break;
}
}
}
self.note = @"";
UIButton *cancelBtn = [UIButton buttonWithType: UIButtonTypeSystem];
[cancelBtn setTitle: ICLocalized(@"Cancel") forState: UIControlStateNormal];
cancelBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[cancelBtn addTarget:self action:@selector(dismissContactController) forControlEvents:UIControlEventTouchUpInside];
contactController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: cancelBtn];
if (push) {
[controller.navigationController pushViewController:contactController animated:YES];
}else{
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: contactController];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[controller presentViewController:nav animated:YES completion:nil];
}
}
- (void)dismissContactController {
if (self.contactPush) {
[self.contactController.navigationController popViewControllerAnimated:YES];
}else{
[self.contactController.navigationController dismissViewControllerAnimated:YES completion:nil];
}
}
- (UIViewController *)currentVC{
UIViewController *result = nil;
UIWindow * window = [UIApplication sharedApplication].windows.lastObject;
//app默认windowLevel是UIWindowLevelNormal,如果不是,找到UIWindowLevelNormal的
if (window.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow * tmpWin in windows)
{
if (tmpWin.windowLevel == UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
id nextResponder = nil;
UIViewController *appRootVC=window.rootViewController;
// 如果是present上来的appRootVC.presentedViewController 不为nil
if (appRootVC.presentedViewController) {
nextResponder = appRootVC.presentedViewController;
}else{
if ([window subviews].count > 0) {//防止崩溃
UIView *frontView = [[window subviews] lastObject];
nextResponder = [frontView nextResponder]; // 这方法下面有详解 </span>
}
}
if ([nextResponder isKindOfClass:[UITabBarController class]]){
UITabBarController * tabbar = (UITabBarController *)nextResponder;
UINavigationController * nav = (UINavigationController *)tabbar.viewControllers[tabbar.selectedIndex];
// UINavigationController * nav = tabbar.selectedViewController ; 上下两种写法都行
result=nav.childViewControllers.lastObject;
}else if ([nextResponder isKindOfClass:[UINavigationController class]]){
UIViewController * nav = (UIViewController *)nextResponder;
result = nav.childViewControllers.lastObject;
}else if ([nextResponder isKindOfClass:[UIWindow class]]){
result = window.rootViewController;
if ([result isKindOfClass:[UINavigationController class]]){
UIViewController * nav = (UIViewController *)result;
result = nav.childViewControllers.lastObject;
}
}else{
result = nextResponder;
}
return result;
}
@end
//
// PYHDocument.h
// superCleaner
//
// Created by GY.Z on 2020/7/6.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol PYHDocumentDelegate <NSObject>
-(void)docGetiCloudContactsMethods:(NSData *)obj fileInfo:(NSDictionary *)fileInfo;
@end
@interface PYHDocument : UIDocument
//文档的二进制数据
@property (nonatomic, strong) NSData *saveData;
//文档存入空间的名字
@property (nonatomic, copy) NSString *saveFileName;
@property(nonatomic,weak)id <PYHDocumentDelegate> delegate;
@end
NS_ASSUME_NONNULL_END
//
// PYHDocument.m
// superCleaner
//
// Created by GY.Z on 2020/7/6.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "PYHDocument.h"
@interface PYHDocument ()
//存储空间地址
@property (nonatomic, strong) NSURL *container;
@end
@implementation PYHDocument
- (instancetype)initWithFileURL:(NSURL *)url {
if (self = [super initWithFileURL:url]) {
self.container = url;
}
return self;
}
- (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError * _Nullable __autoreleasing *)outError {
//提取数据 这里的数据解析和存入数据的时候配套
NSLog(@"%@-%@",contents,typeName);
//1.根据存入处理 这里得到取出数据格式 严谨一些当然是进行相关判断
NSFileWrapper *apper = (NSFileWrapper *)contents;
//2.对数据进行解析
[apper.fileWrappers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSFileWrapper * _Nonnull obj, BOOL * _Nonnull stop) {
NSLog(@"对数据进行解析 = %@-=-=-=-=%@",obj.filename,obj.fileAttributes);
if (self.delegate && [self.delegate respondsToSelector:@selector(docGetiCloudContactsMethods:fileInfo:)]) {
[self.delegate docGetiCloudContactsMethods:obj.regularFileContents fileInfo:obj.fileAttributes];
}
}];
return YES;
}
- (id)contentsForType:(NSString *)typeName error:(NSError * _Nullable __autoreleasing *)outError {
//写入数据
NSLog(@"写入数据 = %@",typeName);
//1.获取目录
NSFileWrapper *wrapper = [[NSFileWrapper alloc] initWithURL:self.container options:NSFileWrapperReadingImmediate error:nil];
//1-1.目录获取失败 证明没有指定目录 那么创建一个
if (!wrapper) {
wrapper = [[NSFileWrapper alloc]initDirectoryWithFileWrappers:@{}];
}
//2.配置储存文档及文档名
if (self.saveData && self.saveFileName) {
//这里遇到的问题是重复文件不会覆盖,然后系统进行了文件名的处理。使目录中,存入了同样的数据。
NSFileWrapper *preWrapper = [wrapper.fileWrappers objectForKey:self.saveFileName];
if (preWrapper) {
[wrapper removeFileWrapper:preWrapper];
}
NSFileWrapper *dataWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:self.saveData];
dataWrapper.preferredFilename = self.saveFileName;
[wrapper addFileWrapper:dataWrapper];
}
return wrapper;
}
@end
//
// ICContactBackupController.h
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactBackupController : UIViewController
@property (nonatomic, strong) NSMutableArray<CNContact *> *contacts;
@end
NS_ASSUME_NONNULL_END
//
// ICContactBackupController.m
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactBackupController.h"
#import "ICContactsTool.h"
#import "ICContactsBackupCell.h"
#import "ICContactsBackupHeader.h"
#import "ICContactsBackup.h"
#import "ICContactsBackupSubController.h"
static NSString * const ICContactsBackupCellID = @"ICContactsBackupCellID";
@interface ICContactBackupController ()<UITableViewDataSource, UITableViewDelegate,ICContactsToolDelegate>
@property (strong, nonatomic) UIButton *backupButton;
@property (nonatomic, strong) UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong)UIButton *deleteButton;
@property(nonatomic,strong)ICContactsTool *tools;
@end
@implementation ICContactBackupController
-(NSMutableArray *)dataArray
{
if (!_dataArray) {
_dataArray = [[NSMutableArray alloc] init];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self setupUI];
}
-(void)setupUI
{
self.navigationItem.title = ICLocalized(@"BackupContact");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:ICLocalized(@"ChooseAll") style:UIBarButtonItemStyleDone target:self action:@selector(chooseAction)];
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style: UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 50;
self.tableView.tableFooterView = [[UIView alloc] init];
// [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView registerNib:[UINib nibWithNibName:@"ICContactsBackupCell" bundle:nil] forCellReuseIdentifier:ICContactsBackupCellID];
self.deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.deleteButton setTitle:ICLocalized(@"BackupImmediately") forState:UIControlStateNormal];
[self.deleteButton setBackgroundImage:[UIImage imageNamed:@"global_green_btn_bg"] forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(backupAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.deleteButton];
self.deleteButton.hidden = NO;
[self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.bottom.equalTo(@(-40));
make.height.equalTo(@62);
make.width.equalTo(@343);
}];
ICContactsBackupHeader *header = [[ICContactsBackupHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 110)];
[self.tableView setTableHeaderView:header];
self.tools = [ICContactsTool shareInstance];
self.tools.delegate = self;
[self.tools loadiCloudDirectory];
}
-(void)chooseAction
{
NSString *name = self.navigationItem.rightBarButtonItem.title;
BOOL choose;
if ([name isEqualToString:ICLocalized(@"ChooseAll")]) {
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"CancelAll");
choose = YES;
}else{
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"ChooseAll");
choose = NO;
}
for (ICContactsBackup *model in self.dataArray) {
model.choose = choose;
}
[self queryChooseContact];
[self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ICContactsBackupCell *cell = [tableView dequeueReusableCellWithIdentifier:ICContactsBackupCellID forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (self.dataArray.count) {
ICContactsBackup *model = self.dataArray[indexPath.row];
cell.model = model;
[cell.button addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
-(void)cellChooseAction:(UIButton *)sender
{
ICContactsBackupCell *cell = (ICContactsBackupCell *)sender.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
// NSLog(@"点击的是第%ld = row",indexPath.row);
ICContactsBackup *model = self.dataArray[indexPath.row];
model.choose = !model.choose;
[self queryChooseContact];
[self.tableView reloadData];
}
-(void)queryChooseContact
{
[self.deleteButton setTitle:ICLocalized(@"BackupImmediately") forState:UIControlStateNormal];
for (ICContactsBackup *model in self.dataArray) {
if (model.choose) {
[self.deleteButton setTitle:ICLocalized(@"DeleteSelected") forState:UIControlStateNormal];
break;
}
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[MobClick event:@"contact_backup_file_click"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ICContactsBackup *model = self.dataArray[indexPath.row];
[self.tools getiCloudContactsPath:model.kMDItemURL];
}
/// Delegate
-(void)getiCloudContactsMethods:(NSData *)obj fileInfo:(nonnull NSDictionary *)fileInfo
{
// NSLog(@"fileInfo = %@",fileInfo);
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:obj];
// NSLog(@"contacts = %@",arr);
ICContactsBackupSubController *vc = [ICContactsBackupSubController new];
vc.contacts = arr;
[self.navigationController pushViewController:vc animated:YES];
}
-(void)getiCloudList:(NSArray *)lists
{
NSLog(@"lists = %@",lists);
if (lists.count == 0){
[self.deleteButton setTitle:ICLocalized(@"BackupImmediately") forState:UIControlStateNormal];
}
[self.dataArray removeAllObjects];
NSMutableArray *temp =@[].mutableCopy;
for (NSDictionary *dict in lists) {
ICContactsBackup *model = [ICContactsBackup new];
[model setValuesForKeysWithDictionary:dict];
NSString *name = dict[@"kMDItemFSName"];
if ([name containsString:@"Contacts-"]) {
NSArray *arr = [name componentsSeparatedByString:@"-"];
if (arr.count > 1) {
model.timestamp = arr[1];
}else{
model.timestamp = @"0";
}
}
[temp addObject:model];
}
/// 按时间排序
NSArray *dataArr = [temp sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
ICContactsBackup *model1 = (ICContactsBackup *)obj1;
ICContactsBackup *model2 = (ICContactsBackup *)obj2;
if ([model1.timestamp integerValue] < [model2.timestamp integerValue]) {
return NSOrderedDescending;
}else if ([model1.timestamp integerValue] > [model2.timestamp integerValue]){
return NSOrderedAscending;
}
return NSOrderedSame;
}];
[self.dataArray addObjectsFromArray:dataArr];
[self.tableView reloadData];
}
- (void)backupAction:(UIButton *)sender {
NSString *name = self.deleteButton.titleLabel.text;
if ([name isEqualToString:ICLocalized(@"BackupImmediately")]) {
[MobClick event:@"contact_backup_now"];
NSLog(@"立即备份");
ICContactsTool *tools = [ICContactsTool shareInstance];
NSString *time = [tools getNowTimeTimestamp];
[tools synciCloudContactsFileName:time];
}else{
NSLog(@"删除所选");
[MobClick event:@"contact_backup_file_delete"];
if (self.dataArray.count == 0) return;
for (ICContactsBackup *model in self.dataArray) {
if (model.choose) {
[self.tools deleteiCloudContactsUrlFile:model.kMDItemURL];
}
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tools loadiCloudDirectory];
});
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
-(NSString *)getRandomStr
{
char data[6];
for (int x=0;x < 6;data[x++] = (char)('A' + (arc4random_uniform(26))));
NSString *randomStr = [[NSString alloc] initWithBytes:data length:6 encoding:NSUTF8StringEncoding];
NSString *string = [NSString stringWithFormat:@"%@",randomStr];
return string;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// ICContactIncompleteController.h
// superCleaner
//
// Created by Mazy on 2020/7/3.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactIncompleteController : UIViewController
@property (nonatomic, strong) NSMutableArray<CNContact *> *contacts;
@end
NS_ASSUME_NONNULL_END
//
// ICContactIncompleteController.m
// superCleaner
//
// Created by Mazy on 2020/7/3.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactIncompleteController.h"
#import <ContactsUI/ContactsUI.h>
#import "ICContactsIncompleteCell.h"
#import "ICContactListModel.h"
#import "Masonry.h"
#import "ICContactsTool.h"
static NSString * const ICContactsIncompleteCellID = @"ICContactsIncompleteCellID";
@interface ICContactIncompleteController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong)UIButton *deleteButton;
@end
@implementation ICContactIncompleteController
-(NSMutableArray *)dataArray
{
if (!_dataArray) {
_dataArray = [[NSMutableArray alloc] init];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUI];
[self groupsSources];
}
-(void)setupUI
{
self.navigationItem.title = ICLocalized(@"AddressInComplete");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:ICLocalized(@"ChooseAll") style:UIBarButtonItemStyleDone target:self action:@selector(chooseAction)];
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style: UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 90;
self.tableView.tableFooterView = [[UIView alloc] init];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView registerNib:[UINib nibWithNibName:@"ICContactsIncompleteCell" bundle:nil] forCellReuseIdentifier:ICContactsIncompleteCellID];
self.deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.deleteButton setTitle:ICLocalized(@"DeleteSelected") forState:UIControlStateNormal];
[self.deleteButton setBackgroundImage:[UIImage imageNamed:@"global_green_btn_bg"] forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.deleteButton];
self.deleteButton.hidden = YES;
[self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.bottom.equalTo(@(-40));
make.height.equalTo(@62);
make.width.equalTo(@343);
}];
}
-(void)groupsSources
{
[self.dataArray removeAllObjects];
for (CNContact *con in self.contacts) {
ICContactListModel *model = [ICContactListModel new];
model.contact = con;
model.choose = NO;
[self.dataArray addObject:model];
}
[self.tableView reloadData];
}
-(void)deleteAction
{
[MobClick event:@"contact_incomplete_delete_all"];
NSInteger idx = 0;
for (ICContactListModel *model in self.dataArray) {
if (model.choose) {
idx ++;
}
}
// NSString *key = [NSString stringWithFormat:@"%ld",(long)[[ICContactsTool shareInstance] getCurrentDay]];
// NSUbiquitousKeyValueStore *keyValueStore = [NSUbiquitousKeyValueStore defaultStore];
// NSString *count = [keyValueStore objectForKey:[NSString stringWithFormat:@"delete_%@",key]];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ICLocalized(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
NSString *delete = [NSString stringWithFormat:@"%@(%ld)",ICLocalized(@"Delete"),(long)idx];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:delete style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[MobClick event:@"contact_incomplete_delete_select"];
// if ([count integerValue] > 0) {
// if (idx > [count integerValue]) {
// [MBProgressHUD showMessage:[NSString stringWithFormat:@"剩余删除次数为%@",count]];
// return ;
// }else{
// NSString *value = [NSString stringWithFormat:@"%ld",(long)[count integerValue] - idx];
// [keyValueStore setObject:value forKey:[NSString stringWithFormat:@"delete_%@",key]];
// [keyValueStore synchronize];
// }
// }else{
// [MBProgressHUD showMessage:@"剩余删除次数为0"];
// return ;
// }
for (ICContactListModel *model in self.dataArray) {
if (model.choose) {
CNMutableContact *contact = (CNMutableContact *)[model.contact mutableCopy];
[[ICContactsTool shareInstance] deleteContact:contact];
}
}
[self fetchContacts];
}];
// NSString *msg = [NSString stringWithFormat:@"每日限制:5\n剩余:%@",count];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:ICLocalized(@"DeleteContact") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:cancelAction];
[alert addAction:sureAction];
[self presentViewController:alert animated:YES completion:nil];
}
// 查询是否有选中的联系人
-(void)queryChooseContact
{
self.deleteButton.hidden = YES;
for (ICContactListModel *model in self.dataArray) {
if (model.choose) {
self.deleteButton.hidden = NO;
break;
}
}
}
- (void)fetchContacts {
self.contacts = [NSMutableArray array];
NSArray *array = [[ICContactsTool shareInstance] fetchContacts];
for (CNContact *con in array) {
if (con.phoneNumbers.count <= 0) {
[self.contacts addObject:con];
}
}
[self groupsSources];
}
-(void)chooseAction
{
NSString *name = self.navigationItem.rightBarButtonItem.title;
if ([name isEqualToString:ICLocalized(@"ChooseAll")]) {
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"CancelAll");
[self exchangeChooseState:YES];
}else{
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"ChooseAll");
[self exchangeChooseState:NO];
}
[self queryChooseContact];
[self.tableView reloadData];
}
-(void)exchangeChooseState:(BOOL)state
{
for (ICContactListModel *model in self.dataArray) {
model.choose = state;
}
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] init];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ICContactsIncompleteCell *cell = [tableView dequeueReusableCellWithIdentifier:ICContactsIncompleteCellID forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (self.dataArray.count) {
ICContactListModel *model = self.dataArray[indexPath.row];
cell.model = model;
[cell.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
-(void)cellChooseAction:(UIButton *)sender
{
ICContactsIncompleteCell *cell = (ICContactsIncompleteCell *)sender.superview.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
// NSLog(@"点击的是第%ld = row",indexPath.row);
ICContactListModel *model = self.dataArray[indexPath.row];
model.choose = !model.choose;
[self queryChooseContact];
[self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:true];
if (self.dataArray.count == 0) return;
ICContactListModel *model = self.dataArray[indexPath.row];
//1.创建Contact对象,必须是可变的
CNContactViewController *contactController = [CNContactViewController viewControllerForContact:model.contact];
// contactController.delegate = self;
/// 是否显示打电话、发短信等按钮
contactController.allowsActions = YES;
/// 能否修改数据
contactController.allowsEditing = YES;
/// 是否显示联系人的关联联系人
contactController.shouldShowLinkedContacts = true;
[contactController viewDidLoad];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: contactController];
UIButton *cancelBtn = [UIButton buttonWithType: UIButtonTypeSystem];
[cancelBtn setTitle:ICLocalized(@"Cancel") forState: UIControlStateNormal];
cancelBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[cancelBtn addTarget:self action:@selector(dismissContactController) forControlEvents:UIControlEventTouchUpInside];
contactController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: cancelBtn];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:nil];
}
- (void)dismissContactController {
[self.navigationController dismissViewControllerAnimated:true completion:nil];
}
@end
//
// ICContactListViewController.h
// superCleaner
//
// Created by Mazy on 2020/7/2.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactListViewController : UIViewController
@property (nonatomic, strong) NSMutableArray<CNContact *> *contacts;
@end
NS_ASSUME_NONNULL_END
//
// ICContactListViewController.m
// superCleaner
//
// Created by Mazy on 2020/7/2.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactListViewController.h"
#import <ContactsUI/ContactsUI.h>
#import "BMChineseSort.h"
#import "ICContactsListCell.h"
#import "ICContactListModel.h"
#import "Masonry.h"
#import "ICContactsTool.h"
static NSString * const ICContactsListCellID = @"ICContactsListCellID";
@interface ICContactListViewController () <UITableViewDataSource, UITableViewDelegate, CNContactViewControllerDelegate,UISearchResultsUpdating>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSArray *keys;
@property (nonatomic, strong) CNContactStore *contactStore;
@property(nonatomic,strong)NSMutableArray *firstLetterArray;
@property(nonatomic,strong)NSMutableArray *sortedModelArr;
@property(nonatomic,assign)NSInteger chooseCount;
@property(nonatomic,strong)UIButton *deleteButton;
@property (strong, nonatomic)UISearchController *searchController;
@property(nonatomic,strong)NSMutableArray *searchArray;
@end
@implementation ICContactListViewController
-(NSMutableArray *)searchArray
{
if (!_searchArray) {
_searchArray = [NSMutableArray array];
}
return _searchArray;
}
-(NSMutableArray *)firstLetterArray
{
if (!_firstLetterArray) {
_firstLetterArray = [NSMutableArray array];
}
return _firstLetterArray;
}
-(NSMutableArray *)sortedModelArr
{
if (!_sortedModelArr) {
_sortedModelArr = [NSMutableArray array];
}
return _sortedModelArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = ICLocalized(@"Contacts");
[self setupUI];
[self groupsSources];
}
-(void)setupUI
{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:ICLocalized(@"Choose") style:UIBarButtonItemStyleDone target:self action:@selector(chooseAction)];
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style: UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 50;
self.tableView.tableFooterView = [[UIView alloc] init];
[self.tableView registerNib:[UINib nibWithNibName:@"ICContactsListCell" bundle:nil] forCellReuseIdentifier:ICContactsListCellID];
self.deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.deleteButton setTitle:ICLocalized(@"DeleteSelected") forState:UIControlStateNormal];
[self.deleteButton setBackgroundImage:[UIImage imageNamed:@"global_green_btn_bg"] forState:UIControlStateNormal];
[self.deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.deleteButton];
self.deleteButton.hidden = YES;
[self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.bottom.equalTo(@(-40));
make.height.equalTo(@62);
make.width.equalTo(@343);
}];
[self setupSearchBar];
}
-(void)setupSearchBar
{
_searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
//设置代理
_searchController.searchResultsUpdater = self;
//设置UISearchController的显示属性,以下3个属性默认为YES
//搜索时,背景变暗色
_searchController.dimsBackgroundDuringPresentation = NO;
//搜索时,背景变模糊
_searchController.obscuresBackgroundDuringPresentation = NO;
//隐藏导航栏
_searchController.hidesNavigationBarDuringPresentation = YES;
_searchController.searchBar.backgroundColor = [UIColor whiteColor];
_searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
_searchController.searchBar.placeholder = ICLocalized(@"Name");
_searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 74.0);
self.tableView.tableHeaderView = _searchController.searchBar;
}
-(void)deleteAction {
if ([ICUserManager shared].isMember) {
NSInteger idx = 0;
for (NSArray *arr in self.sortedModelArr) {
for (ICContactListModel *model in arr) {
if (model.choose) {
idx ++;
}
}
}
if (idx == 0) {
return;
}
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ICLocalized(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[self cancelAction];
}];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:ICLocalized(@"Delete") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[MobClick event:@"contact_delete_action"];
for (NSArray *arr in self.sortedModelArr) {
for (ICContactListModel *model in arr) {
if (model.choose) {
CNMutableContact *contact = (CNMutableContact *)[model.contact mutableCopy];
[[ICContactsTool shareInstance] deleteContact:contact];
}
}
}
[self fetchContacts];
}];
NSString *title = [NSString stringWithFormat:@"%@ %ld %@",ICLocalized(@"Delete"),(long)idx,ICLocalized(@"ContactCount")];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:ICLocalized(@"DeleteDescription") preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:cancelAction];
[alert addAction:sureAction];
[self presentViewController:alert animated:YES completion:nil];
} else {
ICIAPViewController *iapVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICIAPViewController"];
ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:iapVC];
[self presentViewController:navc animated:true completion:nil];
}
}
-(void)chooseAction
{
self.chooseCount ++;
NSString *name = self.navigationItem.rightBarButtonItem.title;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:ICLocalized(@"Cancel") style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];
if (self.chooseCount > 1 && [name isEqualToString:ICLocalized(@"ChooseAll")]) {
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"CancelAll");
[self exchangeChooseState:YES];
}else{
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"ChooseAll");
[self exchangeChooseState:NO];
}
self.deleteButton.hidden = NO;
[self.tableView reloadData];
}
// 更改联系人状态
-(void)exchangeChooseState:(BOOL)state
{
for (NSArray *arr in self.sortedModelArr) {
for (ICContactListModel *model in arr) {
model.choose = state;
}
}
[self.tableView reloadData];
}
-(void)cancelAction
{
[MobClick event:@"contact_delete_action"];
self.chooseCount = 0;
self.deleteButton.hidden = YES;
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"Choose");
[self exchangeChooseState:NO];
[self.tableView reloadData];
}
// 排序
-(void)groupsSources
{
[self.firstLetterArray removeAllObjects];
[self.sortedModelArr removeAllObjects];
[BMChineseSort sortAndGroup:self.contacts key:@"familyName" finish:^(bool isSuccess, NSMutableArray *unGroupedArr, NSMutableArray *sectionTitleArr, NSMutableArray<NSMutableArray *> *sortedObjArr) {
if (isSuccess) {
self.firstLetterArray = sectionTitleArr;
for (NSArray *arr in sortedObjArr) {
NSMutableArray *modelArr = [[NSMutableArray alloc] init];
for (CNContact *con in arr) {
ICContactListModel *model = [ICContactListModel new];
model.contact = con;
model.choose = NO;
[modelArr addObject:model];
}
[self.sortedModelArr addObject:modelArr];
}
[self.tableView reloadData];
}
}];
}
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSLog(@"%@",searchController.searchBar.text);
CNContactStore *store = [[CNContactStore alloc] init];
CNContactFetchRequest *fetchRequest = [[CNContactFetchRequest alloc] initWithKeysToFetch: [self keys]];
fetchRequest.predicate = [CNContact predicateForContactsMatchingName:searchController.searchBar.text];
[self.searchArray removeAllObjects];
NSMutableArray *arr = @[].mutableCopy;
[store enumerateContactsWithFetchRequest:fetchRequest error:nil usingBlock:^(CNContact * _Nonnull contact, BOOL * _Nonnull stop) {
[arr addObject:contact];
}];
for (CNContact *con in arr) {
ICContactListModel *model = [ICContactListModel new];
model.contact = con;
model.choose = NO;
[self.searchArray addObject:model];
}
[self.tableView reloadData];
}
//section的titleHeader
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (self.searchController.active) {
return nil;
}
return self.firstLetterArray[section];
}
//section行数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (self.searchController.active) {
return 1;
}
return self.firstLetterArray.count;
}
//每组section个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (self.searchController.active) {
return self.searchArray.count;
}
return [self.sortedModelArr[section] count];
}
//section右侧index数组
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
if (self.searchController.active) {
return @[];
}
return self.firstLetterArray;
}
//点击右侧索引表项时调用 索引与section的对应关系
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
return index;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
//返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ICContactsListCell *cell = [tableView dequeueReusableCellWithIdentifier:ICContactsListCellID];
if (self.searchController.active) {
if (self.searchArray.count) {
ICContactListModel *model = self.searchArray[indexPath.row];
cell.model = model;
cell.chooseCount = self.chooseCount;
[cell.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
}else if(self.sortedModelArr.count){
ICContactListModel *model = self.sortedModelArr[indexPath.section][indexPath.row];
cell.model = model;
cell.chooseCount = self.chooseCount;
[cell.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
-(void)cellChooseAction:(UIButton *)sender
{
[MobClick event:@"contact_select_action"];
ICContactsListCell *cell = (ICContactsListCell *)sender.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
// NSLog(@"点击的是第%ld = section,第%ld = row",indexPath.section,indexPath.row);
if (self.searchController.active) {
ICContactListModel *model = self.searchArray[indexPath.row];
model.choose = !model.choose;
}else{
ICContactListModel *model = self.sortedModelArr[indexPath.section][indexPath.row];
model.choose = !model.choose;
}
[self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:true];
ICContactListModel *model;
if (self.searchController.active) {
model = self.searchArray[indexPath.row];
}else{
model = self.sortedModelArr[indexPath.section][indexPath.row];
}
self.searchController.active = NO;
//1.创建Contact对象,必须是可变的
CNContactViewController *contactController = [CNContactViewController viewControllerForContact:model.contact];
contactController.delegate = self;
/// 是否显示打电话、发短信等按钮
contactController.allowsActions = YES;
/// 能否修改数据
contactController.allowsEditing = YES;
/// 是否显示联系人的关联联系人
contactController.shouldShowLinkedContacts = true;
[contactController viewDidLoad];
// UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: contactController];
UIButton *cancelBtn = [UIButton buttonWithType: UIButtonTypeSystem];
cancelBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[cancelBtn setTitle:@"取消" forState: UIControlStateNormal];
[cancelBtn addTarget:self action:@selector(dismissContactController) forControlEvents:UIControlEventTouchUpInside];
contactController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: cancelBtn];
// nav.modalPresentationStyle = UIModalPresentationFormSheet;
// [self presentViewController:nav animated:YES completion:nil];
[self.navigationController pushViewController:contactController animated:YES];
}
- (void)dismissContactController {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- CNContactPickerDelegate
/*!
* @abstract Called when the user selects a single property.
* @discussion Return @c NO if you do not want anything to be done or if you are handling the actions yourself.
* @return @c YES if you want the default action performed for the property otherwise return @c NO.
*/
- (BOOL)contactViewController:(CNContactViewController *)viewController shouldPerformDefaultActionForContactProperty:(CNContactProperty *)property {
return true;
}
/*!
* @abstract Called when the view has completed.
* @discussion If creating a new contact, the new contact added to the contacts list will be passed.
* If adding to an existing contact, the existing contact will be passed.
* @note It is up to the delegate to dismiss the view controller.
*/
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact {
}
- (NSArray *)keys
{
if (!_keys) {
_keys = @[[CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName],
CNContactPhoneNumbersKey,
CNContactOrganizationNameKey,
CNContactDepartmentNameKey,
CNContactJobTitleKey,
CNContactPhoneticGivenNameKey,
CNContactPhoneticFamilyNameKey,
CNContactPhoneticMiddleNameKey,
CNContactImageDataKey,
CNContactThumbnailImageDataKey,
CNContactEmailAddressesKey,
CNContactPostalAddressesKey,
CNContactBirthdayKey,
CNContactNonGregorianBirthdayKey,
CNContactInstantMessageAddressesKey,
CNContactSocialProfilesKey,
CNContactRelationsKey,
CNContactUrlAddressesKey, CNContactViewController.descriptorForRequiredKeys];
}
return _keys;
}
- (void)fetchContacts {
self.contacts = [NSMutableArray array];
NSArray *contacts = [[ICContactsTool shareInstance] fetchContacts];
[self.contacts addObjectsFromArray:contacts];
[self groupsSources];
}
@end
//
// ICContactRepetViewController.h
// superCleaner
//
// Created by Mazy on 2020/7/3.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactRepeatViewController : UIViewController
@property (nonatomic, strong) NSArray<NSArray<CNContact *> *> *dataSoruce;
@end
NS_ASSUME_NONNULL_END
//
// ICContactRepetViewController.m
// superCleaner
//
// Created by Mazy on 2020/7/3.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactRepeatViewController.h"
#import <ContactsUI/ContactsUI.h>
#import "ICContactsRepeatCell.h"
#import "Masonry.h"
#import "ICContactListModel.h"
#import "ICContactsRepeatHeader.h"
#import "ICContactsTool.h"
static NSString * const ICContactsRepeatCellID = @"ICContactsRepeatCellID";
@interface ICContactRepeatViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong)UIButton *mergeButton;
@end
@implementation ICContactRepeatViewController
- (NSMutableArray *)dataArray
{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setupUI];
}
-(void)setupUI
{
self.navigationItem.title = ICLocalized(@"RepeatContact");
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:ICLocalized(@"ChooseAll") style:UIBarButtonItemStyleDone target:self action:@selector(chooseAction)];
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style: UITableViewStyleGrouped];
[self.view addSubview:self.tableView];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 90;
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView registerNib:[UINib nibWithNibName:@"ICContactsRepeatCell" bundle:nil] forCellReuseIdentifier:ICContactsRepeatCellID];
[self.tableView registerClass:[ICContactsRepeatHeader class] forHeaderFooterViewReuseIdentifier:@"header"];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@16);
make.right.equalTo(@(-16));
make.top.bottom.equalTo(@0);
}];
self.mergeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.mergeButton setTitle:ICLocalized(@"Merge") forState:UIControlStateNormal];
[self.mergeButton setBackgroundImage:[UIImage imageNamed:@"global_green_btn_bg"] forState:UIControlStateNormal];
[self.mergeButton addTarget:self action:@selector(mergeAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.mergeButton];
self.mergeButton.hidden = YES;
[self.mergeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.bottom.equalTo(@(-40));
make.height.equalTo(@62);
make.width.equalTo(@343);
}];
[self.dataArray removeAllObjects];
for (NSArray *arr in self.dataSoruce) {
NSMutableArray *modelArr = [[NSMutableArray alloc] init];
for (CNContact *con in arr) {
ICContactListModel *model = [ICContactListModel new];
model.contact = con;
model.choose = NO;
[modelArr addObject:model];
}
[self.dataArray addObject:modelArr];
}
[self.tableView reloadData];
}
-(void)chooseAction
{
NSString *name = self.navigationItem.rightBarButtonItem.title;
if ([name isEqualToString:ICLocalized(@"ChooseAll")]) {
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"CancelAll");
[self exchangeChooseState:YES];
}else{
self.navigationItem.rightBarButtonItem.title = ICLocalized(@"ChooseAll");
[self exchangeChooseState:NO];
}
[self queryChooseContact];
[self.tableView reloadData];
}
// 查询是否有选中的联系人
-(void)queryChooseContact
{
self.mergeButton.hidden = YES;
NSInteger idx = 0;
for (NSArray *arr in self.dataArray) {
for (ICContactListModel *model in arr) {
if (model.choose) {
idx ++;
if (idx > 1) {
self.mergeButton.hidden = NO;
break;
}
}
}
}
}
-(void)exchangeChooseState:(BOOL)state
{
for (NSArray *arr in self.dataArray) {
for (ICContactListModel *model in arr) {
model.choose = state;
}
}
[self.tableView reloadData];
}
-(void)mergeAction
{
[MobClick event:@"contact_repeat_combine"];
// NSString *key = [NSString stringWithFormat:@"%ld",(long)[[ICContactsTool shareInstance] getCurrentDay]];
// NSUbiquitousKeyValueStore *keyValueStore = [NSUbiquitousKeyValueStore defaultStore];
// NSString *count = [keyValueStore objectForKey:[NSString stringWithFormat:@"merge_%@",key]];
NSInteger index = 0;
for (NSArray *arr in self.dataArray) {
for (ICContactListModel *model in arr) {
if (model.choose) {
index ++;
break;
}
}
}
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ICLocalized(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
NSString *delete = [NSString stringWithFormat:@"%@(%ld)",ICLocalized(@"Merge"),(long)index];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:delete style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// if ([count integerValue] > 0) {
// if (index > [count integerValue]) {
// [MBProgressHUD showMessage:[NSString stringWithFormat:@"剩余删除次数为%@",count]];
// return ;
// }else{
// NSString *value = [NSString stringWithFormat:@"%ld",(long)[count integerValue] - index];
// [keyValueStore setObject:value forKey:[NSString stringWithFormat:@"delete_%@",key]];
// [keyValueStore synchronize];
// }
// }else{
// [MBProgressHUD showMessage:@"剩余删除次数为0"];
// return ;
// }
NSString *name = @"";
for (NSArray *arr in self.dataArray) {
NSInteger idx = 0;
for (ICContactListModel *model in arr) {
if (model.choose) {
name = [name stringByAppendingFormat:@"%@ ",model.contact.familyName];
}
}
for (ICContactListModel *model in arr) {
if (model.choose) {
CNMutableContact *contact = (CNMutableContact *)[model.contact mutableCopy];
if (idx == 0) {
contact.note = name;
[[ICContactsTool shareInstance] updateContact:contact];
// NSString *value = [NSString stringWithFormat:@"%ld",(long)[count integerValue] - index];
// [keyValueStore setObject:value forKey:[NSString stringWithFormat:@"merge_%@",key]];
// [keyValueStore synchronize];
}else{
[[ICContactsTool shareInstance] deleteContact:contact];
}
}
idx ++;
}
}
[self fetchContacts];
}];
// NSString *msg = [NSString stringWithFormat:@"每日限制:5\n剩余:%@",count];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:ICLocalized(@"MergeContact") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:cancelAction];
[alert addAction:sureAction];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)fetchContacts {
NSMutableArray *contacts = [NSMutableArray array];
NSArray *array = [[ICContactsTool shareInstance] fetchContacts];
[contacts addObjectsFromArray:array];
NSMutableArray *contArrays = [NSMutableArray array];
for (NSArray *arr in [self groupAction:contacts]) {
if (arr.count > 1) {
NSMutableArray *temp = [NSMutableArray array];
for (NSDictionary *dict in arr) {
CNContact *con = dict[@"contact"];
if (con.phoneNumbers.count != 0) {
[temp addObject:dict[@"contact"]];
}
}
if (![contArrays containsObject:temp] && temp.count) {
[contArrays addObject:temp];
}
}
[self.dataArray removeAllObjects];
for (NSArray *arr in contArrays) {
NSMutableArray *modelArr = [[NSMutableArray alloc] init];
for (CNContact *con in arr) {
ICContactListModel *model = [ICContactListModel new];
model.contact = con;
model.choose = NO;
[modelArr addObject:model];
}
[self.dataArray addObject:modelArr];
}
}
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.dataArray[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 130;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 15;
}
-(void)selectAllAction:(UIButton *)sender
{
BOOL flag;
if ([sender.titleLabel.text isEqualToString:ICLocalized(@"CancelAll")]) {
flag = NO;
}else{
flag = YES;
}
NSArray *array = self.dataArray[sender.tag];
for (ICContactListModel *model in array) {
model.choose = flag;
}
[self queryChooseContact];
[self.tableView reloadData];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
ICContactsRepeatHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
[header.selectBtn addTarget:self action:@selector(selectAllAction:) forControlEvents:UIControlEventTouchUpInside];
header.selectBtn.tag = section;
header.contacts = self.dataArray[section];
// NSArray *array = self.dataArray[section];
// NSString *name = @"";
// NSString *phone = @"";
// NSString *subPhone = @"";
// NSInteger idx = 0;
// [header.selectBtn setTitle:@"取消全选" forState:UIControlStateNormal];
// for (ICContactListModel *model in array) {
// subPhone = [subPhone stringByAppendingFormat:@"%@ ",model.contact.familyName];
// if (model.contact.phoneNumbers.count) {
// NSArray *phones = model.contact.phoneNumbers;
// CNLabeledValue *labeledValue = phones[0];
// CNPhoneNumber *phoneNumer = labeledValue.value;
// NSString *phoneNumber = phoneNumer.stringValue;
// phone = [NSString stringWithFormat:@"%@", phoneNumber];
// }
// if (model.choose) {
// idx ++;
// name = [name stringByAppendingFormat:@"%@ ",model.contact.familyName];
// }else{
// [header.selectBtn setTitle:@"选择全部" forState:UIControlStateNormal];
// }
// }
// if (idx > 1) {
// [header updateName:name updatePhone:phone];
// }else{
// [header updateName:subPhone updatePhone:phone];
// }
//
return header;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 32, 15)];
v.backgroundColor = kMassColorAlpha(0.15);
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:v.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = v.bounds;
maskLayer.path = maskPath.CGPath;
v.layer.mask = maskLayer;
return v;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ICContactsRepeatCell *cell = [tableView dequeueReusableCellWithIdentifier:ICContactsRepeatCellID forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (self.dataArray.count) {
ICContactListModel *model = self.dataArray[indexPath.section][indexPath.row];
cell.model = model;
[cell.chooseButton addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
-(void)cellChooseAction:(UIButton *)sender
{
ICContactsRepeatCell *cell = (ICContactsRepeatCell *)sender.superview.superview.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
// NSLog(@"点击的是第%ld = section,第%ld = row",indexPath.section,indexPath.row);
ICContactListModel *model = self.dataArray[indexPath.section][indexPath.row];
model.choose = !model.choose;
[self queryChooseContact];
[self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:true];
if (self.dataArray.count == 0) return;
ICContactListModel *model = self.dataArray[indexPath.section][indexPath.row];
[[ICContactsTool shareInstance] enterContactsDetail:model.contact controller:self push:NO];
}
//对返回的数据进行区分筛选
- (NSMutableArray *)groupAction:(NSMutableArray *)arr {
__block NSMutableArray *groupArr = [NSMutableArray array];
NSMutableArray *array = [[NSMutableArray alloc] init];
for (CNContact *contact in arr) {
NSArray *phones = contact.phoneNumbers;
if (phones.count) {
CNLabeledValue *labeledValue = phones[0];
CNPhoneNumber *phoneNumer = labeledValue.value;
NSString *phoneNumber = phoneNumer.stringValue;
if (phoneNumber.length) {
[array addObject:@{@"phoneNumber":phoneNumber,@"contact":contact}];
}else{
[array addObject:@{@"phoneNumber":@"number",@"contact":contact}];
}
}else{
[array addObject:@{@"phoneNumber":@"number",@"contact":contact}];
}
}
[array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *phoneNumber = obj[@"phoneNumber"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"phoneNumber = %@", phoneNumber];
NSArray *tempArr = [NSArray arrayWithArray:[array filteredArrayUsingPredicate:predicate]];
[groupArr addObject:tempArr];
}];
return groupArr;
}
@end
//
// ICContactsBackupSubController.h
// superCleaner
//
// Created by GY.Z on 2020/7/8.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactsBackupSubController : UIViewController
@property (nonatomic, strong) NSArray *contacts;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsBackupSubController.m
// superCleaner
//
// Created by GY.Z on 2020/7/8.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsBackupSubController.h"
#import <ContactsUI/ContactsUI.h>
#import "BMChineseSort.h"
#import "ICContactsListCell.h"
#import "ICContactListModel.h"
static NSString * const ICContactsListSubCellID = @"ICContactsListSubCellID";
@interface ICContactsBackupSubController ()<UITableViewDataSource, UITableViewDelegate, CNContactViewControllerDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;
@end
@implementation ICContactsBackupSubController
-(NSMutableArray *)dataArray
{
if (!_dataArray) {
_dataArray = [[NSMutableArray alloc] init];
}
return _dataArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"备份";
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style: UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 50;
self.tableView.tableFooterView = [[UIView alloc] init];
[self.tableView registerNib:[UINib nibWithNibName:@"ICContactsListCell" bundle:nil] forCellReuseIdentifier:ICContactsListSubCellID];
for (CNContact *contact in self.contacts) {
ICContactListModel *model = [ICContactListModel new];
model.contact = contact;
[self.dataArray addObject:model];
}
NSLog(@"%@",self.contacts);
[self.tableView reloadData];
}
//section行数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//每组section个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01;
}
//返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ICContactsListCell *cell = [tableView dequeueReusableCellWithIdentifier:ICContactsListSubCellID];
if (self.contacts.count) {
ICContactListModel *model = self.dataArray[indexPath.row];
cell.model = model;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:true];
ICContactListModel *model = self.dataArray[indexPath.row];
//1.创建Contact对象,必须是可变的
CNContactViewController *contactController = [CNContactViewController viewControllerForContact:model.contact];
contactController.delegate = self;
/// 是否显示打电话、发短信等按钮
contactController.allowsActions = YES;
/// 能否修改数据
contactController.allowsEditing = YES;
/// 是否显示联系人的关联联系人
contactController.shouldShowLinkedContacts = true;
[contactController viewDidLoad];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: contactController];
UIButton *cancelBtn = [UIButton buttonWithType: UIButtonTypeSystem];
cancelBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[cancelBtn setTitle:@"取消" forState: UIControlStateNormal];
[cancelBtn addTarget:self action:@selector(dismissContactController) forControlEvents:UIControlEventTouchUpInside];
contactController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: cancelBtn];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:nil];
}
- (void)dismissContactController {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
@end
//
// ICContactsViewController.h
// superCleaner
//
// Created by Mazy on 2020/7/2.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactsViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
//
// ICContactsViewController.m
// superCleaner
//
// Created by Mazy on 2020/7/2.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsViewController.h"
#import "ICContactManageViewCell.h"
#import "ICContactListViewController.h"
#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
#import "ICContactRepeatViewController.h"
#import "ICContactIncompleteController.h"
#import "ICContactBackupController.h"
#import "ICContactsTool.h"
#include <sys/param.h>
#include <sys/mount.h>
@interface ICContactsViewController () <UITableViewDataSource, UITableViewDelegate, CNContactViewControllerDelegate>
@property (nonatomic, strong) UITableView *tableView;
/// 联系人
@property (nonatomic, strong) NSMutableArray<CNContact *> *contacts;
/// 重复联系人
@property (nonatomic, strong) NSMutableArray<NSArray<CNContact *> *> *repeatDataSoruce;
/// 不完整联系人
@property (nonatomic, strong) NSMutableArray<CNContact *> *incompleteContacts;
@end
@implementation ICContactsViewController
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:false animated:true];
BOOL enable = [[ICContactsTool shareInstance] contactsAuthStatus];
if (enable) {
CNContactStore *contactStore = [[CNContactStore alloc] init];
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
[self fetchContacts];
// 成功
} else {
// 失败
}
}];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = ICLocalized(@"ManagementContact");
self.tableView = [[UITableView alloc] initWithFrame: self.view.bounds style: UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 90;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
[self.tableView registerNib: [UINib nibWithNibName:@"ICContactManageViewCell" bundle:nil] forCellReuseIdentifier:@"ICContactManageViewCell"];
// /// 自动备份
// NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"auto_icloud_backup"];
// if ([value isEqualToString:@"auto_backup"]) {
// [[ICContactsTool shareInstance] autoSavesssiCloudFileName:@"001"];
// }
//
// 注册删除次数
[[ICContactsTool shareInstance] registerDeleteOrMergeCount];
}
-(NSString *)convertToJsonData:(NSDictionary *)dict
{
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString;
if (!jsonData) {
NSLog(@"%@",error);
}else{
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
NSRange range = {0,jsonString.length};
//去掉字符串中的空格
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
NSRange range2 = {0,mutStr.length};
//去掉字符串中的换行符
[mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
return mutStr;
}
- (void)fetchContacts {
self.contacts = [NSMutableArray array];
self.incompleteContacts = [NSMutableArray array];
NSArray *contacts = [[ICContactsTool shareInstance] fetchContacts];
[self.contacts addObjectsFromArray:contacts];
for (CNContact *con in self.contacts) {
if (con.phoneNumbers.count <= 0) {
[self.incompleteContacts addObject:con];
}
}
self.repeatDataSoruce = [NSMutableArray array];
for (NSArray *arr in [self groupAction:self.contacts]) {
if (arr.count > 1) {
NSMutableArray *temp = [NSMutableArray array];
for (NSDictionary *dict in arr) {
CNContact *con = dict[@"contact"];
if (con.phoneNumbers.count != 0) {
[temp addObject:dict[@"contact"]];
}
}
if (![self.repeatDataSoruce containsObject:temp] && temp.count) {
[self.repeatDataSoruce addObject:temp];
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
//对返回的数据进行区分筛选
- (NSMutableArray *)groupAction:(NSMutableArray *)arr {
__block NSMutableArray *groupArr = [NSMutableArray array];
NSMutableArray *array = [[NSMutableArray alloc] init];
for (CNContact *contact in arr) {
NSArray *phones = contact.phoneNumbers;
if (phones.count) {
CNLabeledValue *labeledValue = phones[0];
CNPhoneNumber *phoneNumer = labeledValue.value;
NSString *phoneNumber = phoneNumer.stringValue;
if (phoneNumber.length) {
[array addObject:@{@"phoneNumber":phoneNumber,@"contact":contact}];
}else{
[array addObject:@{@"phoneNumber":@"number",@"contact":contact}];
}
}else{
[array addObject:@{@"phoneNumber":@"number",@"contact":contact}];
}
}
[array enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *phoneNumber = obj[@"phoneNumber"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"phoneNumber = %@", phoneNumber];
NSArray *tempArr = [NSArray arrayWithArray:[array filteredArrayUsingPredicate:predicate]];
[groupArr addObject:tempArr];
}];
return groupArr;
}
# pragma UITableViewDataSource, UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 15;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ICContactManageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ICContactManageViewCell" forIndexPath:indexPath];
switch (indexPath.section) {
case 0:
cell.subTitleLabel.hidden = true;
switch (indexPath.row) {
case 0:
cell.mainTitleLabel.text = ICLocalized(@"Contacts");
cell.countLabel.hidden = false;
cell.countLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.contacts.count];
break;
default:
cell.countLabel.hidden = true;
cell.mainTitleLabel.text = ICLocalized(@"BackupContact");
break;
}
break;
default:
cell.countLabel.hidden = false;
switch (indexPath.row) {
case 0:
cell.mainTitleLabel.text = ICLocalized(@"Repeat");
cell.countLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.repeatDataSoruce.count];
cell.subTitleLabel.text = ICLocalized(@"NamePhoneEmail");
break;
default:
cell.mainTitleLabel.text = ICLocalized(@"AddressInComplete");
cell.countLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.incompleteContacts.count];
cell.subTitleLabel.text = ICLocalized(@"NoNamePhoneEmail");
break;
}
break;
}
return cell;
}
/*
if ([ICUserManager shared].isMember) {
} else {
ICIAPViewController *iapVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICIAPViewController"];
ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:iapVC];
[self presentViewController:navc animated:true completion:nil];
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:true];
if (indexPath.section == 0 && indexPath.row == 0) {
ICContactListViewController *listVC = [[ICContactListViewController alloc] init];
listVC.contacts = self.contacts;
[self.navigationController pushViewController:listVC animated:true];
} else if (indexPath.section == 0 && indexPath.row == 1) {
[MobClick event:@"contact_backup"];
if ([ICUserManager shared].isMember) {
ICContactBackupController *listVC = [[ICContactBackupController alloc] init];
listVC.contacts = self.contacts;
[self.navigationController pushViewController:listVC animated:true];
} else {
ICIAPViewController *iapVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICIAPViewController"];
ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:iapVC];
[self presentViewController:navc animated:true completion:nil];
}
} else if (indexPath.section == 1 && indexPath.row == 0) {
[MobClick event:@"contact_repeat_number"];
if ([ICUserManager shared].isMember) {
ICContactRepeatViewController *repeatVC = [[ICContactRepeatViewController alloc] init];
repeatVC.dataSoruce = self.repeatDataSoruce;
[self.navigationController pushViewController:repeatVC animated:true];
} else {
ICIAPViewController *iapVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICIAPViewController"];
ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:iapVC];
[self presentViewController:navc animated:true completion:nil];
}
} else if (indexPath.section == 1 && indexPath.row == 1) {
[MobClick event:@"contact_incomplete"];
if ([ICUserManager shared].isMember) {
ICContactIncompleteController *incompleteVC = [[ICContactIncompleteController alloc] init];
incompleteVC.contacts = self.incompleteContacts;
[self.navigationController pushViewController:incompleteVC animated:true];
} else {
ICIAPViewController *iapVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICIAPViewController"];
ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:iapVC];
[self presentViewController:navc animated:true completion:nil];
}
}
}
@end
//
// ICContactManageViewCell.h
// superCleaner
//
// Created by Mazy on 2020/7/2.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "superCleaner-Swift.h"
NS_ASSUME_NONNULL_BEGIN
@interface ICContactManageViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *mainTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (weak, nonatomic) IBOutlet UIView *mainContentView;
@property (weak, nonatomic) IBOutlet GSPregressView *progressView;
@end
NS_ASSUME_NONNULL_END
//
// ICContactManageViewCell.m
// superCleaner
//
// Created by Mazy on 2020/7/2.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactManageViewCell.h"
@implementation ICContactManageViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.mainContentView.layer.cornerRadius = 8;
// self.progressView.layer.cornerRadius = 8;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="ICContactManageViewCell" rowHeight="85" id="KGk-i7-Jjw" customClass="ICContactManageViewCell">
<rect key="frame" x="0.0" y="0.0" width="375" height="85"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="375" height="85"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z4n-SS-9ZS">
<rect key="frame" x="15" y="10" width="345" height="70"/>
<subviews>
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="CeS-TO-M82" customClass="GSPregressView" customModule="Quick_Cleaner" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="345" height="70"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="strokeStart">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="strokeColor">
<color key="value" red="0.14901960780000001" green="0.74117647060000003" blue="0.36078431370000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="3" translatesAutoresizingMaskIntoConstraints="NO" id="9U1-oG-9e7">
<rect key="frame" x="16" y="15.5" width="93" height="39.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="联系人" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AXU-3d-3i7">
<rect key="frame" x="0.0" y="0.0" width="93" height="19.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<color key="textColor" red="0.13333333333333333" green="0.16078431372549018" blue="0.23921568627450979" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="姓名 号码 邮件" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ndd-Rb-FQK">
<rect key="frame" x="0.0" y="22.5" width="93" height="17"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="viewFlipsideBackgroundColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="global_cell_indicator" translatesAutoresizingMaskIntoConstraints="NO" id="OO7-0A-Cpy">
<rect key="frame" x="328" y="29" width="7" height="12"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3eW-Hg-KK1">
<rect key="frame" x="308.5" y="26" width="9.5" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.52156862745098043" green="0.54509803921568623" blue="0.61176470588235299" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.14901960784313725" green="0.74117647058823533" blue="0.36078431372549019" alpha="0.10000000000000001" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="9U1-oG-9e7" firstAttribute="leading" secondItem="z4n-SS-9ZS" secondAttribute="leading" constant="16" id="HHY-lc-Cnb"/>
<constraint firstAttribute="trailing" secondItem="CeS-TO-M82" secondAttribute="trailing" id="RaE-La-fcy"/>
<constraint firstItem="CeS-TO-M82" firstAttribute="top" secondItem="z4n-SS-9ZS" secondAttribute="top" id="YE9-K4-dnh"/>
<constraint firstAttribute="bottom" secondItem="CeS-TO-M82" secondAttribute="bottom" id="aSv-ch-991"/>
<constraint firstItem="9U1-oG-9e7" firstAttribute="centerY" secondItem="z4n-SS-9ZS" secondAttribute="centerY" id="d3t-MN-QDk"/>
<constraint firstItem="OO7-0A-Cpy" firstAttribute="leading" secondItem="3eW-Hg-KK1" secondAttribute="trailing" constant="10" id="ehf-bF-jPT"/>
<constraint firstItem="CeS-TO-M82" firstAttribute="leading" secondItem="z4n-SS-9ZS" secondAttribute="leading" id="ijP-5H-ybn"/>
<constraint firstAttribute="trailing" secondItem="OO7-0A-Cpy" secondAttribute="trailing" constant="10" id="qQk-mO-xUm"/>
<constraint firstItem="3eW-Hg-KK1" firstAttribute="centerY" secondItem="z4n-SS-9ZS" secondAttribute="centerY" id="y4P-y9-qsi"/>
<constraint firstItem="OO7-0A-Cpy" firstAttribute="centerY" secondItem="z4n-SS-9ZS" secondAttribute="centerY" id="yCf-AB-rQF"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="massBackgroundColorWithAlpha">
<real key="value" value="0.14999999999999999"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="z4n-SS-9ZS" secondAttribute="bottom" constant="5" id="0ng-LG-6gG"/>
<constraint firstItem="z4n-SS-9ZS" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="15" id="Lc9-3s-aYS"/>
<constraint firstItem="z4n-SS-9ZS" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="g2p-ao-hp9"/>
<constraint firstAttribute="trailing" secondItem="z4n-SS-9ZS" secondAttribute="trailing" constant="15" id="xgo-cF-KAD"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
<inset key="separatorInset" minX="1000" minY="0.0" maxX="0.0" maxY="0.0"/>
<connections>
<outlet property="countLabel" destination="3eW-Hg-KK1" id="BHw-2W-mQV"/>
<outlet property="mainContentView" destination="z4n-SS-9ZS" id="uaa-90-OFu"/>
<outlet property="mainTitleLabel" destination="AXU-3d-3i7" id="TTo-tZ-Ck1"/>
<outlet property="progressView" destination="CeS-TO-M82" id="2xH-GO-fQ9"/>
<outlet property="subTitleLabel" destination="Ndd-Rb-FQK" id="PyL-xC-Jg7"/>
</connections>
<point key="canvasLocation" x="177.536231884058" y="157.70089285714286"/>
</tableViewCell>
</objects>
<resources>
<image name="global_cell_indicator" width="7" height="12"/>
</resources>
</document>
//
// ICContactsBackupCell.h
// superCleaner
//
// Created by GY.Z on 2020/7/7.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class ICContactsBackup;
@interface ICContactsBackupCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *button;
@property(nonatomic,strong)ICContactsBackup *model;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsBackupCell.m
// superCleaner
//
// Created by GY.Z on 2020/7/7.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsBackupCell.h"
#import "ICContactsBackup.h"
@interface ICContactsBackupCell ()
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *noteLabel;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@end
@implementation ICContactsBackupCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setModel:(ICContactsBackup *)model
{
_model = model;
self.dateLabel.text = [NSString stringWithFormat:@"%@",[self convertStrToTime:model.timestamp]];
self.noteLabel.text = [NSString stringWithFormat:@"%ldKB",(long)[model.kMDItemFSSize integerValue]/1000];
if (model.choose) {
[self.button setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
}else{
[self.button setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
}
}
- (NSString *)convertStrToTime:(NSString *)timeStr
{
long long time=[timeStr longLongValue];
NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *timeString=[formatter stringFromDate:date];
return timeString;
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="ICContactsBackupCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sYw-tN-Bgp">
<rect key="frame" x="10" y="5" width="30" height="40"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="XKU-zC-N4D"/>
</constraints>
<state key="normal" image="contact_choose"/>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xfq-Eb-3tY">
<rect key="frame" x="295" y="0.0" width="0.0" height="50"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" white="0.5" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="global_cell_indicator" translatesAutoresizingMaskIntoConstraints="NO" id="5jw-ga-IMg">
<rect key="frame" x="300" y="20" width="10" height="10"/>
<constraints>
<constraint firstAttribute="height" constant="10" id="BcT-QY-hl8"/>
<constraint firstAttribute="width" constant="10" id="lVn-SP-mGc"/>
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="lEa-Lz-5op">
<rect key="frame" x="45" y="11" width="163.5" height="28"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2020年7月7日 下午5:02:37" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Gu-nn-XRH">
<rect key="frame" x="0.0" y="0.0" width="163.5" height="16"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="35.9KB [张广义的 iPhone]" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zOK-Ma-fu3">
<rect key="frame" x="0.0" y="16" width="163.5" height="12"/>
<fontDescription key="fontDescription" type="system" pointSize="10"/>
<color key="textColor" white="0.59999999999999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="xfq-Eb-3tY" secondAttribute="bottom" id="AJl-LV-cWH"/>
<constraint firstAttribute="bottom" secondItem="sYw-tN-Bgp" secondAttribute="bottom" constant="5" id="EZ3-4u-txn"/>
<constraint firstItem="lEa-Lz-5op" firstAttribute="leading" secondItem="sYw-tN-Bgp" secondAttribute="trailing" constant="5" id="FrE-2n-WVY"/>
<constraint firstItem="lEa-Lz-5op" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="R8p-iH-dNz"/>
<constraint firstItem="sYw-tN-Bgp" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="5" id="UDR-TN-ghX"/>
<constraint firstItem="sYw-tN-Bgp" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="VVi-Aw-Exb"/>
<constraint firstItem="5jw-ga-IMg" firstAttribute="leading" secondItem="xfq-Eb-3tY" secondAttribute="trailing" constant="5" id="W1n-g6-9sS"/>
<constraint firstAttribute="trailing" secondItem="5jw-ga-IMg" secondAttribute="trailing" constant="10" id="eQ7-o6-Kyo"/>
<constraint firstItem="xfq-Eb-3tY" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="jCY-yD-IBh"/>
<constraint firstItem="sYw-tN-Bgp" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="lJs-cC-yiT"/>
<constraint firstItem="5jw-ga-IMg" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="sL2-Ff-AN4"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
<connections>
<outlet property="button" destination="sYw-tN-Bgp" id="Qpx-IL-KeY"/>
<outlet property="countLabel" destination="xfq-Eb-3tY" id="1GP-4l-izg"/>
<outlet property="dateLabel" destination="4Gu-nn-XRH" id="cPt-KR-3F6"/>
<outlet property="noteLabel" destination="zOK-Ma-fu3" id="lf9-XQ-74c"/>
</connections>
<point key="canvasLocation" x="137.68115942028987" y="132.58928571428572"/>
</tableViewCell>
</objects>
<resources>
<image name="contact_choose" width="20" height="20"/>
<image name="global_cell_indicator" width="7" height="12"/>
</resources>
</document>
//
// ICContactsBackupHeader.h
// superCleaner
//
// Created by GY.Z on 2020/7/7.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactsBackupHeader : UIView
@end
NS_ASSUME_NONNULL_END
//
// ICContactsBackupHeader.m
// superCleaner
//
// Created by GY.Z on 2020/7/7.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsBackupHeader.h"
#import "ICContactsTool.h"
@interface ICContactsBackupHeader ()
@property (strong, nonatomic) UISwitch *switchButton;
@end
@implementation ICContactsBackupHeader
-(instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setupSubviews];
}
return self;
}
-(void)setupSubviews
{
UIView *line = [[UIView alloc] init];
line.backgroundColor = [UIColor colorWithHexString:@"#E5E7EB"];
[self addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@30);
make.left.right.equalTo(@0);
make.height.equalTo(@0.5);
}];
UILabel *label = [[UILabel alloc] init];
label.text = ICLocalized(@"AutomaticBackup");
label.textColor = [UIColor colorWithHexString:@"#212121"];
label.font = [UIFont systemFontOfSize:16];
[self addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@16);
make.height.equalTo(@44);
make.top.equalTo(line.mas_bottom).offset(0);
}];
self.switchButton = [[UISwitch alloc] init];
[self addSubview:self.switchButton];
self.switchButton.on = NO;
self.switchButton.onTintColor = kMassColor;
[self.switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
[self.switchButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(label);
make.right.equalTo(@(-16));
}];
NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"auto_icloud_backup"];
if ([value isEqualToString:@"auto_backup"]) {
self.switchButton.on = YES;
}
UIView *bottomLine = [[UIView alloc] init];
bottomLine.backgroundColor = [UIColor colorWithHexString:@"#E5E7EB"];
[self addSubview:bottomLine];
[bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(@0);
make.top.equalTo(label.mas_bottom).offset(0);
make.height.equalTo(@0.5);
}];
UILabel *subLabel = [[UILabel alloc] init];
subLabel.text = ICLocalized(@"BackupDescription");
subLabel.numberOfLines = 2;
subLabel.textColor = [UIColor colorWithHexString:@"#858B9C"];
subLabel.textAlignment = NSTextAlignmentCenter;
subLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:subLabel];
[subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(@0);
make.height.equalTo(@30);
make.top.equalTo(bottomLine.mas_bottom).offset(0);
}];
}
- (void)switchAction:(UISwitch *)sender {
// sender.on = !sender.on;
if (sender.on) {
NSLog(@"自动备份");
[[NSUserDefaults standardUserDefaults] setObject:@"auto_backup" forKey:@"auto_icloud_backup"];
ICContactsTool *tools = [ICContactsTool shareInstance];
NSString *time = [tools getNowTimeTimestamp];
[tools synciCloudContactsFileName:time];
}else{
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"auto_icloud_backup"];
NSLog(@"取消");
}
}
@end
//
// ICContactsIncompleteCell.h
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^SelectionClosure)(BOOL granted);
@class ICContactListModel;
@interface ICContactsIncompleteCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *chooseBtn;
@property(nonatomic,strong)ICContactListModel *model;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLabel;
@property (nonatomic, strong) NSDateFormatter *formatter;
-(void)configWithEvent: (EKEvent *)event seleted: (BOOL)isSelected;
-(void)configWithReminder: (EKReminder *)reminder seleted: (BOOL)isSelected;
@property(nonatomic, copy)SelectionClosure selectedClosure;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsIncompleteCell.m
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsIncompleteCell.h"
#import "ICContactListModel.h"
@implementation ICContactsIncompleteCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setModel:(ICContactListModel *)model
{
_model = model;
self.nameLabel.text = [NSString stringWithFormat:@"%@%@", model.contact.familyName, model.contact.givenName];
self.chooseBtn.selected = model.choose;
if (model.choose) {
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
}else{
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
}
}
-(void)configWithEvent: (EKEvent *)event seleted: (BOOL)isSelected {
self.subTitleLabel.text = event.title;
self.subTitleLabel.hidden = false;
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy-MM-dd HH:dd";
NSString *startTime = [self.formatter stringFromDate: event.startDate];
self.nameLabel.text = startTime;
if (isSelected) {
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
}else{
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
}
[self.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)cellChooseAction: (UIButton *)button {
button.selected = !button.isSelected;
// if (button.isSelected) {
// [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
// }else{
// [self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
// }
if (self.selectedClosure) {
self.selectedClosure(button.isSelected);
}
}
-(void)configWithReminder: (EKReminder *)reminder seleted: (BOOL)isSelected {
self.subTitleLabel.text = reminder.title;
self.subTitleLabel.hidden = false;
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy-MM-dd HH:dd";
NSString *completionDate = [self.formatter stringFromDate: reminder.completionDate];
self.nameLabel.text = completionDate;
if (isSelected) {
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
}else{
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
}
[self.chooseBtn addTarget:self action:@selector(cellChooseAction:) forControlEvents:UIControlEventTouchUpInside];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="ICContactsIncompleteCell">
<rect key="frame" x="0.0" y="0.0" width="375" height="90"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="375" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="RXl-B2-dqC">
<rect key="frame" x="16" y="10" width="343" height="75"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pQv-9Z-sZb">
<rect key="frame" x="299" y="15.5" width="44" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="MGJ-1l-63n"/>
<constraint firstAttribute="width" constant="44" id="stm-QL-Lgg"/>
</constraints>
<state key="normal" image="contact_choose"/>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="tsm-Yt-gH3">
<rect key="frame" x="16" y="28" width="49" height="19.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="联系人" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gWn-Ef-sJr">
<rect key="frame" x="0.0" y="0.0" width="49" height="19.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<color key="textColor" red="0.13333333333333333" green="0.16078431372549018" blue="0.23921568627450979" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="联系人" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Obh-e1-CFe">
<rect key="frame" x="0.0" y="19.5" width="49" height="0.0"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.1333333333" green="0.16078431369999999" blue="0.23921568630000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" red="0.14901960780000001" green="0.74117647060000003" blue="0.36078431370000003" alpha="0.096586385350318466" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="tsm-Yt-gH3" firstAttribute="centerY" secondItem="RXl-B2-dqC" secondAttribute="centerY" id="94f-Nl-4DH"/>
<constraint firstAttribute="trailing" secondItem="pQv-9Z-sZb" secondAttribute="trailing" id="Vxk-a3-IYS"/>
<constraint firstItem="pQv-9Z-sZb" firstAttribute="centerY" secondItem="RXl-B2-dqC" secondAttribute="centerY" id="b05-y3-ZkF"/>
<constraint firstItem="tsm-Yt-gH3" firstAttribute="leading" secondItem="RXl-B2-dqC" secondAttribute="leading" constant="16" id="v17-a5-By6"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="massBackgroundColorWithAlpha">
<real key="value" value="0.14999999999999999"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="RXl-B2-dqC" secondAttribute="trailing" constant="16" id="2FL-gC-j3b"/>
<constraint firstItem="RXl-B2-dqC" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="OEi-Yq-3q3"/>
<constraint firstAttribute="bottom" secondItem="RXl-B2-dqC" secondAttribute="bottom" constant="5" id="QTy-IL-fNb"/>
<constraint firstItem="RXl-B2-dqC" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="hso-3c-Uiw"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
<connections>
<outlet property="chooseBtn" destination="pQv-9Z-sZb" id="ruq-oz-wLi"/>
<outlet property="nameLabel" destination="gWn-Ef-sJr" id="qDr-NP-lDh"/>
<outlet property="subTitleLabel" destination="Obh-e1-CFe" id="uAn-ls-2qc"/>
</connections>
<point key="canvasLocation" x="136.95652173913044" y="96.428571428571431"/>
</tableViewCell>
</objects>
<resources>
<image name="contact_choose" width="22" height="22"/>
</resources>
</document>
//
// ICContactsListCell.h
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class ICContactListModel;
@interface ICContactsListCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *chooseBtn;
@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@property (weak, nonatomic) IBOutlet UILabel *nameL;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageLeftMargin;
@property (weak, nonatomic) IBOutlet UILabel *iconLabel;
@property(nonatomic,strong)ICContactListModel *model;
@property(nonatomic,assign)NSInteger chooseCount;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsListCell.m
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsListCell.h"
#import "ICContactListModel.h"
@interface ICContactsListCell ()
@end
@implementation ICContactsListCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.chooseBtn.hidden = YES;
}
-(void)setModel:(ICContactListModel *)model
{
_model = model;
self.nameL.text = [NSString stringWithFormat:@"%@%@",model.contact.familyName,model.contact.givenName];
if (model.contact.imageData != nil) {
self.imageV.image = [UIImage imageWithData:[NSData dataWithData:model.contact.imageData]];
self.iconLabel.text = @"";
}else{
self.imageV.image = [UIImage new];
if (model.contact.familyName.length) {
self.iconLabel.text = [model.contact.familyName substringToIndex:1];
}else if (model.contact.givenName.length){
self.iconLabel.text = [model.contact.givenName substringToIndex:1];
}
}
self.chooseBtn.hidden = model.choose;
if (model.choose) {
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
}else{
[self.chooseBtn setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
}
}
-(void)setChooseCount:(NSInteger)chooseCount
{
_chooseCount = chooseCount;
if (chooseCount >= 1) {
self.imageLeftMargin.constant = 48;
self.chooseBtn.hidden = NO;
}else{
self.imageLeftMargin.constant = 16;
self.chooseBtn.hidden = YES;
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="ICContactsListCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PIs-tF-3ro">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<constraints>
<constraint firstAttribute="width" secondItem="PIs-tF-3ro" secondAttribute="height" multiplier="1:1" id="Zi5-NC-wPG"/>
</constraints>
<state key="normal" image="contact_choose"/>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="657-gx-XeG">
<rect key="frame" x="10" y="3" width="44" height="44"/>
<color key="backgroundColor" red="0.49803921568627452" green="0.53333333333333333" blue="0.60784313725490191" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="657-gx-XeG" secondAttribute="height" multiplier="1:1" id="J3S-Be-gcE"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="clipsToBounds" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="22"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="电话" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sZX-cl-YBp">
<rect key="frame" x="64" y="0.0" width="206" height="50"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dbw-qu-kii">
<rect key="frame" x="32" y="25" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" red="0.96862745100000003" green="0.96862745100000003" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="dbw-qu-kii" firstAttribute="centerX" secondItem="657-gx-XeG" secondAttribute="centerX" id="8C8-Fh-3u4"/>
<constraint firstItem="sZX-cl-YBp" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="EQb-Qd-JIs"/>
<constraint firstAttribute="bottom" secondItem="sZX-cl-YBp" secondAttribute="bottom" id="M2H-9z-jrO"/>
<constraint firstAttribute="bottom" secondItem="657-gx-XeG" secondAttribute="bottom" constant="3" id="PBM-A9-xxg"/>
<constraint firstAttribute="bottom" secondItem="PIs-tF-3ro" secondAttribute="bottom" id="Pwd-7n-pvS"/>
<constraint firstAttribute="trailing" secondItem="sZX-cl-YBp" secondAttribute="trailing" constant="50" id="YfA-fr-85E"/>
<constraint firstItem="657-gx-XeG" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="3" id="Z2A-zU-IJX"/>
<constraint firstItem="PIs-tF-3ro" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="a8X-nD-lhK"/>
<constraint firstItem="dbw-qu-kii" firstAttribute="centerY" secondItem="657-gx-XeG" secondAttribute="centerY" id="fTZ-kD-XHz"/>
<constraint firstItem="657-gx-XeG" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="10" id="mTj-fQ-GGa"/>
<constraint firstItem="PIs-tF-3ro" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="rY4-Rp-LdH"/>
<constraint firstItem="sZX-cl-YBp" firstAttribute="leading" secondItem="657-gx-XeG" secondAttribute="trailing" constant="10" id="u9o-HR-tKG"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
<connections>
<outlet property="chooseBtn" destination="PIs-tF-3ro" id="cME-yu-2En"/>
<outlet property="iconLabel" destination="dbw-qu-kii" id="l5n-Sz-2FQ"/>
<outlet property="imageLeftMargin" destination="mTj-fQ-GGa" id="4Tr-3C-sdv"/>
<outlet property="imageV" destination="657-gx-XeG" id="8if-N3-iAI"/>
<outlet property="nameL" destination="sZX-cl-YBp" id="6Z0-BK-BGB"/>
</connections>
<point key="canvasLocation" x="139" y="102"/>
</tableViewCell>
</objects>
<resources>
<image name="contact_choose" width="20" height="20"/>
</resources>
</document>
//
// ICContactsRepeatCell.h
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class ICContactListModel;
@interface ICContactsRepeatCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UIButton *chooseButton;
@property (weak, nonatomic) IBOutlet UIView *contactView;
@property(nonatomic,strong)ICContactListModel *model;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsRepeatCell.m
// superCleaner
//
// Created by GY.Z on 2020/7/4.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsRepeatCell.h"
#import "UIColor+HExtension.h"
#import "ICContactListModel.h"
@implementation ICContactsRepeatCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.contactView.layer.borderColor = [UIColor colorWithHexString:@"#dddddd"].CGColor;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setModel:(ICContactListModel *)model
{
_model = model;
self.nameLabel.text = [NSString stringWithFormat:@"%@%@", model.contact.familyName, model.contact.givenName];
if (model.contact.phoneNumbers.count) {
NSArray *phones = model.contact.phoneNumbers;
CNLabeledValue *labeledValue = phones[0];
CNPhoneNumber *phoneNumer = labeledValue.value;
NSString *phoneNumber = phoneNumer.stringValue;
self.phoneLabel.text = [NSString stringWithFormat:@"%@", phoneNumber];
}else{
self.phoneLabel.text = @"";
}
self.chooseButton.selected = model.choose;
if (model.choose) {
[self.chooseButton setImage:[UIImage imageNamed:@"contact_choosed"] forState:UIControlStateNormal];
}else{
[self.chooseButton setImage:[UIImage imageNamed:@"contact_choose"] forState:UIControlStateNormal];
}
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="ICContactsRepeatCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="70"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="70"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Pj1-TJ-iPf">
<rect key="frame" x="0.0" y="0.0" width="320" height="70"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Xqk-Mw-wbA">
<rect key="frame" x="16" y="5" width="288" height="60"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="68w-dd-tC1">
<rect key="frame" x="244" y="8" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="qbC-hY-nTd"/>
<constraint firstAttribute="height" constant="44" id="yMe-4u-wCZ"/>
</constraints>
<state key="normal" image="contact_choose"/>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="DSr-6j-m3h">
<rect key="frame" x="10" y="13" width="86.5" height="34"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="张" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wMf-Wd-FmU">
<rect key="frame" x="0.0" y="0.0" width="86.5" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.13333333333333333" green="0.16078431372549018" blue="0.23921568627450979" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="18211128646" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1mM-QU-4ZB">
<rect key="frame" x="0.0" y="17" width="86.5" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.13333333333333333" green="0.16078431372549018" blue="0.23921568627450979" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="68w-dd-tC1" firstAttribute="centerY" secondItem="Xqk-Mw-wbA" secondAttribute="centerY" id="216-Vz-PJi"/>
<constraint firstItem="DSr-6j-m3h" firstAttribute="centerY" secondItem="Xqk-Mw-wbA" secondAttribute="centerY" id="R13-Os-mAw"/>
<constraint firstAttribute="trailing" secondItem="68w-dd-tC1" secondAttribute="trailing" id="R96-4s-dbL"/>
<constraint firstItem="DSr-6j-m3h" firstAttribute="leading" secondItem="Xqk-Mw-wbA" secondAttribute="leading" constant="10" id="TIk-k0-EjU"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="clipsToBounds" value="YES"/>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="8"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="layer.borderWidth">
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<color key="backgroundColor" red="0.9137254901960784" green="0.97254901960784312" blue="0.93333333333333335" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="Xqk-Mw-wbA" secondAttribute="trailing" constant="16" id="6KY-Q9-JDf"/>
<constraint firstAttribute="bottom" secondItem="Xqk-Mw-wbA" secondAttribute="bottom" constant="5" id="MZx-Yv-9qu"/>
<constraint firstItem="Xqk-Mw-wbA" firstAttribute="leading" secondItem="Pj1-TJ-iPf" secondAttribute="leading" constant="16" id="VVS-V4-v5v"/>
<constraint firstItem="Xqk-Mw-wbA" firstAttribute="top" secondItem="Pj1-TJ-iPf" secondAttribute="top" constant="5" id="xbF-EF-q8B"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="massBackgroundColorWithAlpha">
<real key="value" value="0.14999999999999999"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="Pj1-TJ-iPf" secondAttribute="trailing" id="CuA-eC-Q30"/>
<constraint firstAttribute="bottom" secondItem="Pj1-TJ-iPf" secondAttribute="bottom" id="HPZ-OO-C7I"/>
<constraint firstItem="Pj1-TJ-iPf" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="JLk-Zr-Kvd"/>
<constraint firstItem="Pj1-TJ-iPf" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="Oam-F3-DVp"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="aW0-zy-SZf"/>
<connections>
<outlet property="chooseButton" destination="68w-dd-tC1" id="Z0J-w4-PED"/>
<outlet property="contactView" destination="Xqk-Mw-wbA" id="hLh-E6-hl4"/>
<outlet property="nameLabel" destination="wMf-Wd-FmU" id="cCq-06-Gy0"/>
<outlet property="phoneLabel" destination="1mM-QU-4ZB" id="27c-Xv-A02"/>
</connections>
<point key="canvasLocation" x="137.68115942028987" y="87.723214285714278"/>
</tableViewCell>
</objects>
<resources>
<image name="contact_choose" width="22" height="22"/>
</resources>
</document>
//
// ICContactsRepeatHeader.h
// superCleaner
//
// Created by GY.Z on 2020/7/6.
// Copyright © 2020 Mazy. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ICContactsRepeatHeader : UITableViewHeaderFooterView
@property(nonatomic,strong)UIButton *selectBtn;
@property(nonatomic,strong)NSArray *contacts;
-(void)updateName:(NSString *)name updatePhone:(NSString *)phone;
@end
NS_ASSUME_NONNULL_END
//
// ICContactsRepeatHeader.m
// superCleaner
//
// Created by GY.Z on 2020/7/6.
// Copyright © 2020 Mazy. All rights reserved.
//
#import "ICContactsRepeatHeader.h"
#import "ICContactListModel.h"
#import <Contacts/Contacts.h>
#import "ICContactsTool.h"
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
@interface ICContactsRepeatHeader ()
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UIView *contView;
@property(nonatomic,strong)UIView *baseView;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UILabel *phoneLabel;
@end
@implementation ICContactsRepeatHeader
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
self.contentView.backgroundColor = [UIColor whiteColor];
self.contView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, kWidth - 32, 120)];
self.contView.backgroundColor = kMassColorAlpha(0.1);
[self.contentView addSubview:self.contView];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.contView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.contView.bounds;
maskLayer.path = maskPath.CGPath;
self.contView.layer.mask = maskLayer;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
[self.contView addGestureRecognizer:tap];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.text = ICLocalized(@"MergedContact");
self.titleLabel.font = [UIFont systemFontOfSize:14];
[self.contView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(@16);
}];
self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.selectBtn setTitle:ICLocalized(@"ChooseAll") forState:UIControlStateNormal];
[self.selectBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
[self.selectBtn setTitleColor:kMassColor forState:UIControlStateNormal];
[self.contView addSubview:self.selectBtn];
[self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(@(-16));
make.top.equalTo(@14);
}];
self.baseView = [[UIView alloc] init];
self.baseView.backgroundColor = kMassColorAlpha(0.3);
[self.contView addSubview:self.baseView];
[self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@16);
make.top.equalTo(@46);
make.right.equalTo(@(-16));
make.height.equalTo(@60);
}];
self.baseView.layer.cornerRadius = 8;
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.text = ICLocalized(@"Name");
self.nameLabel.font = [UIFont systemFontOfSize:14];
[self.baseView addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(@12);
}];
self.phoneLabel = [[UILabel alloc] init];
self.phoneLabel.text = ICLocalized(@"Phone");
self.phoneLabel.font = [UIFont systemFontOfSize:14];
[self.baseView addSubview:self.phoneLabel];
[self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@12);
make.top.equalTo(self.nameLabel.mas_bottom).offset(3);
}];
}
return self;
}
-(void)setContacts:(NSArray *)contacts
{
_contacts = contacts;
NSArray *array = contacts;
NSString *name = @"";
NSString *phone = @"";
NSString *subPhone = @"";
NSInteger idx = 0;
[self.selectBtn setTitle:ICLocalized(@"CancelAll") forState:UIControlStateNormal];
for (ICContactListModel *model in array) {
subPhone = [subPhone stringByAppendingFormat:@"%@ ",model.contact.familyName];
if (model.contact.phoneNumbers.count) {
NSArray *phones = model.contact.phoneNumbers;
CNLabeledValue *labeledValue = phones[0];
CNPhoneNumber *phoneNumer = labeledValue.value;
NSString *phoneNumber = phoneNumer.stringValue;
phone = [NSString stringWithFormat:@"%@", phoneNumber];
}
if (model.choose) {
idx ++;
name = [name stringByAppendingFormat:@"%@ ",model.contact.familyName];
}else{
[self.selectBtn setTitle:ICLocalized(@"ChooseAll") forState:UIControlStateNormal];
}
}
if (idx > 1) {
[self updateName:name updatePhone:phone];
}else{
[self updateName:subPhone updatePhone:phone];
}
}
-(void)updateName:(NSString *)name updatePhone:(NSString *)phone
{
self.nameLabel.text = name;
self.phoneLabel.text = phone;
}
-(void)tapAction
{
NSLog(@"click");
if (self.contacts.count == 0) return ;
ICContactListModel *model = self.contacts[0];
[ICContactsTool shareInstance].note = self.nameLabel.text;
[[ICContactsTool shareInstance] enterContactsDetail:model.contact controller:[self getViewController] push:NO];
}
- (UIViewController *)getViewController {
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController*)nextResponder;
}
}
return nil;
}
@end
......@@ -24,7 +24,7 @@
#import "ICCalendarManageController.h"
#import "StatisticsViewController.h"
#import "SCHomeHeaderView.h"
#import "Data.h"
@interface ICHomeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
......@@ -53,10 +53,15 @@
[[ICUserManager shared] getServiceInfo];
if (!model.isMember) {
Data * data = [[Data alloc] init];
NSDictionary * dic = [[data Read] objectForKey:@"open1close0"];
if ([[dic objectForKey:@"isPayfront"] isEqual:@1]) {
ICIAPViewController *iapVC = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"ICIAPViewController"];
ICNavigationController *navc = [[ICNavigationController alloc] initWithRootViewController:iapVC];
[self presentViewController:navc animated:true completion:nil];
}
}
} failure:^{
......
......@@ -139,20 +139,6 @@ static ICUserManager * manager;
//-(void)getSystemConfigInfo: (void(^)(ZTNovelInfoModel *model))success failure:(void(^)(void))failure {
// [[ZTNetworkTools shared] getWithAction: getSystemConfig parameters:@{} success:^(id _Nonnull response) {
// NSLog(@"getSystemConfig %@", response);
// if ([[response objectForKey:@"status"] intValue] != 200) {
// failure();
// return;
// }
// NSDictionary *dict = response[@"result"][@"data"][@"switch"];
// ZTNovelInfoModel *model = [ZTNovelInfoModel modelWithDic: dict];
// self.novelInfoModel = model;
// success(model);
// } failure:^(NSError * _Nonnull error) {
// NSLog(@"getSystemConfig %@", error);
// failure();
// }];
//}
......@@ -172,6 +158,11 @@ static ICUserManager * manager;
} else {
[data removeDicForKey:@"config"];
}
if ([[[response objectForKey:@"result"] objectForKey:@"data"] objectForKey:@"open1close0"]) {
[data WirteDic:[[[response objectForKey:@"result"] objectForKey:@"data"] objectForKey:@"open1close0"] Key:@"open1close0"];
} else {
[data removeDicForKey:@"open1close0"];
}
}
} failure:^(NSError * _Nonnull error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment