Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderZsq committed Sep 22, 2019
1 parent 846562d commit f161019
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 4 deletions.
26 changes: 26 additions & 0 deletions SQManagement/SQManagement.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
14D633B0233763FF004FD86A /* SQAuthorizationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 14D633AF233763FF004FD86A /* SQAuthorizationManager.m */; };
14D633B52337674F004FD86A /* SQSearchInputView.m in Sources */ = {isa = PBXBuildFile; fileRef = 14D633B22337674F004FD86A /* SQSearchInputView.m */; };
14D633B62337674F004FD86A /* SQSearchInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 14D633B42337674F004FD86A /* SQSearchInputView.xib */; };
14DC37CB23374CFB00867A92 /* SQH1TitleView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 14DC37C923374CFB00867A92 /* SQH1TitleView.xib */; };
14DC37CC23374CFB00867A92 /* SQH1TitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 14DC37CA23374CFB00867A92 /* SQH1TitleView.m */; };
14DC37CF23374DC600867A92 /* SQConnectionsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 14DC37CE23374DC600867A92 /* SQConnectionsViewController.m */; };
Expand All @@ -27,6 +30,11 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
14D633AE233763FF004FD86A /* SQAuthorizationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQAuthorizationManager.h; sourceTree = "<group>"; };
14D633AF233763FF004FD86A /* SQAuthorizationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SQAuthorizationManager.m; sourceTree = "<group>"; };
14D633B22337674F004FD86A /* SQSearchInputView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SQSearchInputView.m; sourceTree = "<group>"; };
14D633B32337674F004FD86A /* SQSearchInputView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQSearchInputView.h; sourceTree = "<group>"; };
14D633B42337674F004FD86A /* SQSearchInputView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SQSearchInputView.xib; sourceTree = "<group>"; };
14DC37C823374CFB00867A92 /* SQH1TitleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQH1TitleView.h; sourceTree = "<group>"; };
14DC37C923374CFB00867A92 /* SQH1TitleView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SQH1TitleView.xib; sourceTree = "<group>"; };
14DC37CA23374CFB00867A92 /* SQH1TitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SQH1TitleView.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -72,9 +80,21 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
14D633B123376549004FD86A /* Tools */ = {
isa = PBXGroup;
children = (
14D633AE233763FF004FD86A /* SQAuthorizationManager.h */,
14D633AF233763FF004FD86A /* SQAuthorizationManager.m */,
);
path = Tools;
sourceTree = "<group>";
};
14DC37D023374F6E00867A92 /* Coms */ = {
isa = PBXGroup;
children = (
14D633B32337674F004FD86A /* SQSearchInputView.h */,
14D633B22337674F004FD86A /* SQSearchInputView.m */,
14D633B42337674F004FD86A /* SQSearchInputView.xib */,
14DC37C823374CFB00867A92 /* SQH1TitleView.h */,
14DC37CA23374CFB00867A92 /* SQH1TitleView.m */,
14DC37C923374CFB00867A92 /* SQH1TitleView.xib */,
Expand Down Expand Up @@ -144,6 +164,7 @@
children = (
14DC37D123374F7700867A92 /* Main */,
14DC37D023374F6E00867A92 /* Coms */,
14D633B123376549004FD86A /* Tools */,
14DC37E423374FC300867A92 /* UI */,
14DC37D423374FA500867A92 /* SQExtension */,
14E97DCE2335014B004FC20D /* Main.storyboard */,
Expand Down Expand Up @@ -231,6 +252,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
14D633B62337674F004FD86A /* SQSearchInputView.xib in Resources */,
14DC37CB23374CFB00867A92 /* SQH1TitleView.xib in Resources */,
14E97DD82335014C004FC20D /* LaunchScreen.storyboard in Resources */,
14E97DD52335014C004FC20D /* Assets.xcassets in Resources */,
Expand Down Expand Up @@ -278,8 +300,10 @@
14E97DC72335014B004FC20D /* AppDelegate.m in Sources */,
14E97DD32335014B004FC20D /* SQManagement.xcdatamodeld in Sources */,
14DC37CC23374CFB00867A92 /* SQH1TitleView.m in Sources */,
14D633B0233763FF004FD86A /* SQAuthorizationManager.m in Sources */,
14DC37E023374FA500867A92 /* NSObject+SQExtension.m in Sources */,
14DC37CF23374DC600867A92 /* SQConnectionsViewController.m in Sources */,
14D633B52337674F004FD86A /* SQSearchInputView.m in Sources */,
14E97DCA2335014B004FC20D /* SceneDelegate.m in Sources */,
14DC37E223374FA500867A92 /* UIImage+SQExtension.m in Sources */,
);
Expand Down Expand Up @@ -425,6 +449,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = BMZP26248F;
INFOPLIST_FILE = SQManagement/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -443,6 +468,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = BMZP26248F;
INFOPLIST_FILE = SQManagement/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "search_icon-2.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions SQManagement/SQManagement/Coms/SQSearchInputView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// SQSearchInputView.h
// SQMagnet
//
// Created by 朱双泉 on 2019/7/12.
// Copyright © 2019 Castie!. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface SQSearchInputView : UIView

+ (instancetype)inputView;

- (void)hookApplicationWillEnterForeground;

@end

NS_ASSUME_NONNULL_END
60 changes: 60 additions & 0 deletions SQManagement/SQManagement/Coms/SQSearchInputView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// SQSearchInputView.m
// SQMagnet
//
// Created by 朱双泉 on 2019/7/12.
// Copyright © 2019 Castie!. All rights reserved.
//

#import "SQSearchInputView.h"
#import "UIColor+SQExtension.h"
#import "NSObject+SQExtension.h"
#import "UIView+SQExtension.h"

@interface SQSearchInputView () <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (nonatomic, strong) NSMutableDictionary *dict;

@end

@implementation SQSearchInputView

+ (instancetype)inputView {
SQSearchInputView *inputView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:nil options:nil].firstObject;
[inputView hookApplicationWillEnterForeground];
return inputView;
}

- (void)awakeFromNib {
[super awakeFromNib];
self.textField.delegate = self;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_icon"]];
UIView *leftView = [UIView new];
leftView.frame = CGRectMake(5, 0, imageView.width + 10, self.textField.height);
imageView.center = leftView.center;
[leftView addSubview:imageView];
self.textField.leftView = leftView;
self.textField.leftViewMode = UITextFieldViewModeAlways;
}

- (void)hookApplicationWillEnterForeground {
if (@available(iOS 13.0, *)) {
self.textField.backgroundColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trait) {
if (trait.userInterfaceStyle == UIUserInterfaceStyleDark) {
return [[UIColor colorWithHexString:@"#1c1c1e"] colorWithAlphaComponent:0.7f];
} else {
return [[UIColor colorWithHexString:@"#eeeeef"] colorWithAlphaComponent:0.7f];
}
}];
self.textField.textColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trait) {
if (trait.userInterfaceStyle == UIUserInterfaceStyleDark) {
return [UIColor whiteColor];
} else {
return [UIColor blackColor];
}
}];
}
}

@end
41 changes: 41 additions & 0 deletions SQManagement/SQManagement/Coms/SQSearchInputView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14868" 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="14824"/>
<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"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="SQSearchInputView">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField autoresizesSubviews="NO" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="搜索你想寻找的人脉~" textAlignment="natural" clearsOnBeginEditing="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="8dJ-T3-HJU">
<rect key="frame" x="15" y="1" width="384" height="32"/>
<color key="backgroundColor" red="0.93333333333333335" green="0.93333333333333335" blue="0.93725490196078431" alpha="0.70473030821917804" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="3d3-6d-CWL"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="search" enablesReturnKeyAutomatically="YES"/>
</textField>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="8dJ-T3-HJU" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="1" id="bVb-n6-cua"/>
<constraint firstItem="8dJ-T3-HJU" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="15" id="kaI-t1-cub"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="8dJ-T3-HJU" secondAttribute="trailing" constant="15" id="n0D-47-VRY"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<connections>
<outlet property="textField" destination="8dJ-T3-HJU" id="fpE-bQ-xW1"/>
</connections>
<point key="canvasLocation" x="139" y="147"/>
</view>
</objects>
</document>
19 changes: 19 additions & 0 deletions SQManagement/SQManagement/Tools/SQAuthorizationManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// SQAuthorizationManager.h
// SQManagement
//
// Created by 朱双泉 on 2019/9/22.
// Copyright © 2019 Castie!. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface SQAuthorizationManager : NSObject

+ (void)fetchContacts: (void(^)(NSString *, NSArray *))callback;

@end

NS_ASSUME_NONNULL_END
42 changes: 42 additions & 0 deletions SQManagement/SQManagement/Tools/SQAuthorizationManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// SQAuthorizationManager.m
// SQManagement
//
// Created by 朱双泉 on 2019/9/22.
// Copyright © 2019 Castie!. All rights reserved.
//

#import "SQAuthorizationManager.h"
#import <Contacts/Contacts.h>

@implementation SQAuthorizationManager

+ (void)fetchContacts:(void (^)(NSString *, NSArray *))callback {
dispatch_async(dispatch_get_main_queue(), ^{
CNContactStore *store = [[CNContactStore alloc] init];
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType: CNEntityTypeContacts];
if (status == CNAuthorizationStatusNotDetermined) {
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
NSLog(@"联系人授权成功");
} else {
NSLog(@"联系人授权失败");
}
}];
}
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactFamilyNameKey, CNContactGivenNameKey,CNContactPhoneNumbersKey]];
[store enumerateContactsWithFetchRequest:request error:nil usingBlock:^(CNContact * _Nonnull contact, BOOL * _Nonnull stop) {
NSString *name = [contact.familyName stringByAppendingString:contact.givenName];
NSMutableArray *phoneNumbers = @[].mutableCopy;
for (CNLabeledValue *phoneNumber in contact.phoneNumbers) {
CNPhoneNumber *phoneNumberValue = phoneNumber.value;
[phoneNumbers addObject:phoneNumberValue.stringValue];
}
if (callback) {
callback(name, phoneNumbers);
}
}];
});
}

@end
34 changes: 30 additions & 4 deletions SQManagement/SQManagement/UI/SQConnectionsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#import "SQConnectionsViewController.h"
#import "UIViewController+SQExtension.h"
#import "SQH1TitleView.h"
#import <Contacts/Contacts.h>
#import "SQSearchInputView.h"
#import "SQAuthorizationManager.h"

@interface SQConnectionsViewController ()
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UIColor *defaultColor;

@property (nonatomic, strong) NSMutableArray *dataSource;
@end

@implementation SQConnectionsViewController
Expand All @@ -31,15 +32,40 @@ - (void)viewDidLoad {
titleLabel.frame = self.titleLabel.frame;
self.navigationItem.titleView = titleLabel;
self.titleLabel = titleLabel;

self.dataSource = @[].mutableCopy;
[SQAuthorizationManager fetchContacts:^(NSString *name, NSArray *phoneNumbers) {
[self.dataSource addObject:name];
[self.tableView reloadData];
}];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) return 0;
else return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
}
cell.textLabel.text = self.dataSource[indexPath.row];
return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0) return [SQH1TitleView viewWithTitle:self.title];
else return nil;
else return [SQSearchInputView inputView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0) return 64;
return 44;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
Expand Down

0 comments on commit f161019

Please sign in to comment.