-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
260 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
SQManagement/SQManagement/Assets.xcassets/search_icon.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Binary file added
BIN
+1.01 KB
SQManagement/SQManagement/Assets.xcassets/search_icon.imageset/search_icon-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters