Skip to content

Commit

Permalink
Added field mask for 'addresses only' and 'addresses with labels'
Browse files Browse the repository at this point in the history
  • Loading branch information
belkevich committed Jan 5, 2016
1 parent 36865c8 commit fdd4f17
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 26 deletions.
10 changes: 10 additions & 0 deletions Example/Objective-C/AddressBook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
2DBA12274B8BFA605F110B91 /* APAddressBookAccessRoutine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAddressBookAccessRoutine.m; sourceTree = "<group>"; };
2DBA125B051EE9D46F45C505 /* APThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APThread.m; sourceTree = "<group>"; };
2DBA12CDF576C49EAEB83108 /* APPhone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APPhone.h; sourceTree = "<group>"; };
2DBA12D09D8CD39546DE39A8 /* APDeprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APDeprecated.h; sourceTree = "<group>"; };
2DBA12DDF7D558CB7281DF82 /* APAddressBook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APAddressBook.m; sourceTree = "<group>"; };
2DBA1306FE1FC39976165204 /* APName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APName.h; sourceTree = "<group>"; };
2DBA131ED390B35AF6A6F826 /* APAddressBook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APAddressBook.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -164,6 +165,14 @@
path = Public;
sourceTree = "<group>";
};
2DBA10E72DB90812D445957A /* Deprecated */ = {
isa = PBXGroup;
children = (
2DBA12D09D8CD39546DE39A8 /* APDeprecated.h */,
);
path = Deprecated;
sourceTree = "<group>";
};
2DBA1693A4961B92662AFC34 /* Private */ = {
isa = PBXGroup;
children = (
Expand All @@ -173,6 +182,7 @@
2DBA1705BC593F92C1870534 /* Wrapper */,
2DBA17FB82D91E188A92BA0E /* Extractors */,
2DBA18B5003E6C7FB8A14478 /* Helpers */,
2DBA10E72DB90812D445957A /* Deprecated */,
);
path = Private;
sourceTree = "<group>";
Expand Down
4 changes: 2 additions & 2 deletions Pod/Core/Private/Builders/APContactBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ - (APContact *)contactWithRecordRef:(ABRecordRef)recordRef fieldMask:(APContactF
{
contact.emails = [self.extractor emailsWithLabels:(fieldMask & APContactFieldEmailsWithLabels)];
}
if (fieldMask & APContactFieldAddresses)
if (fieldMask & APContactFieldAddressesOnly || fieldMask & APContactFieldAddressesWithLabels)
{
contact.addresses = [self.extractor addresses];
contact.addresses = [self.extractor addressesWithLabels:(fieldMask & APContactFieldAddressesWithLabels)];
}
if (fieldMask & APContactFieldSocialProfiles)
{
Expand Down
9 changes: 9 additions & 0 deletions Pod/Core/Private/Deprecated/APDeprecated.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// APDeprecated.h
// AddressBook
//
// Created by Alexey Belkevich on 05.01.16.
// Copyright (c) 2016 alterplay. All rights reserved.
//

#define AP_DEPRECATED(_useInstead) __attribute__((deprecated("Use " #_useInstead " instead")))
2 changes: 1 addition & 1 deletion Pod/Core/Private/Extractors/APContactDataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- (APJob *)job;
- (NSArray *)phonesWithLabels:(BOOL)needLabels;
- (NSArray *)emailsWithLabels:(BOOL)needLabels;
- (NSArray *)addresses;
- (NSArray *)addressesWithLabels:(BOOL)labels;
- (NSArray *)socialProfiles;
- (NSArray *)relatedPersons;
- (NSArray *)linkedRecordIDs;
Expand Down
9 changes: 6 additions & 3 deletions Pod/Core/Private/Extractors/APContactDataExtractor.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ - (NSArray *)emailsWithLabels:(BOOL)needLabels
}];
}

- (NSArray *)addresses
- (NSArray *)addressesWithLabels:(BOOL)needLabels
{
return [self mapMultiValueOfProperty:kABPersonAddressProperty
withBlock:^id(ABMultiValueRef multiValue, CFTypeRef value, CFIndex index)
Expand All @@ -93,8 +93,11 @@ - (NSArray *)addresses
address.zip = dictionary[(__bridge NSString *)kABPersonAddressZIPKey];
address.country = dictionary[(__bridge NSString *)kABPersonAddressCountryKey];
address.countryCode = dictionary[(__bridge NSString *)kABPersonAddressCountryCodeKey];
address.originalLabel = [self originalLabelFromMultiValue:multiValue index:index];
address.localizedLabel = [self localizedLabelFromMultiValue:multiValue index:index];
if (needLabels)
{
address.originalLabel = [self originalLabelFromMultiValue:multiValue index:index];
address.localizedLabel = [self localizedLabelFromMultiValue:multiValue index:index];
}
return address;
}];
}
Expand Down
2 changes: 0 additions & 2 deletions Pod/Core/Public/APAddressBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ typedef void(^APRequestAccessBlock)(BOOL granted, NSError * _Nullable error);
@end


#define AP_DEPRECATED(_useInstead) __attribute__((deprecated("Use " #_useInstead " instead")))

@interface APAddressBook (Deprecated)

+ (void)requestAccess:(nonnull APRequestAccessBlock)completionBlock
Expand Down
40 changes: 22 additions & 18 deletions Pod/Core/Public/Models/APTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright (c) 2014 alterplay. All rights reserved.
//

#import "APDeprecated.h"

typedef NS_ENUM(NSUInteger, APAddressBookAccess)
{
APAddressBookAccessUnknown = 0,
Expand All @@ -15,24 +17,26 @@ typedef NS_ENUM(NSUInteger, APAddressBookAccess)

typedef NS_OPTIONS(NSUInteger, APContactField)
{
APContactFieldName = 1 << 0,
APContactFieldJob = 1 << 1,
APContactFieldThumbnail = 1 << 2,
APContactFieldPhonesOnly = 1 << 3,
APContactFieldPhonesWithLabels = 1 << 4,
APContactFieldEmailsOnly = 1 << 5,
APContactFieldEmailsWithLabels = 1 << 6,
APContactFieldAddresses = 1 << 7,
APContactFieldSocialProfiles = 1 << 8,
APContactFieldBirthday = 1 << 9,
APContactFieldWebsites = 1 << 10,
APContactFieldNote = 1 << 11,
APContactFieldRelatedPersons = 1 << 12,
APContactFieldLinkedRecordIDs = 1 << 13,
APContactFieldSource = 1 << 14,
APContactFieldRecordDate = 1 << 15,
APContactFieldDefault = APContactFieldName | APContactFieldPhonesOnly,
APContactFieldAll = 0xFFFFFFFF
APContactFieldName = 1 << 0,
APContactFieldJob = 1 << 1,
APContactFieldThumbnail = 1 << 2,
APContactFieldPhonesOnly = 1 << 3,
APContactFieldPhonesWithLabels = 1 << 4,
APContactFieldEmailsOnly = 1 << 5,
APContactFieldEmailsWithLabels = 1 << 6,
APContactFieldAddressesWithLabels = 1 << 7,
APContactFieldAddressesOnly = 1 << 8,
APContactFieldAddresses AP_DEPRECATED('APContactFieldAddressesOnly') = APContactFieldAddressesOnly,
APContactFieldSocialProfiles = 1 << 9,
APContactFieldBirthday = 1 << 10,
APContactFieldWebsites = 1 << 11,
APContactFieldNote = 1 << 12,
APContactFieldRelatedPersons = 1 << 13,
APContactFieldLinkedRecordIDs = 1 << 14,
APContactFieldSource = 1 << 15,
APContactFieldRecordDate = 1 << 16,
APContactFieldDefault = APContactFieldName | APContactFieldPhonesOnly,
APContactFieldAll = 0xFFFFFFFF
};

typedef NS_ENUM(NSUInteger, APSocialNetworkType)
Expand Down

0 comments on commit fdd4f17

Please sign in to comment.