Skip to content

Commit

Permalink
Merge pull request #156 from CleverTap/feature/SDK-394-phone-identity
Browse files Browse the repository at this point in the history
Added methods to allow the user to choose Identifier keys for OnUserLogin via plist or Config
  • Loading branch information
akashvercetti authored Feb 7, 2022
2 parents e8dccc7 + ae26865 commit e962c9d
Show file tree
Hide file tree
Showing 306 changed files with 3,584 additions and 18,753 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ ObjCStarter/Podfile.lock

# Swift Package Manager
Package.resolved

Pods
Podfile.lock
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Change Log
All notable changes to this project will be documented in this file.

### [Version 4.0.0](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/4.0.0) (Dec 3, 2021)

### [Version 4.0.0](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/4.0.0) (February 7, 2022)
##### Added
- Adds Custom Proxy Domain functionality for Push Impressions and Events
- Adds support for configurable CleverTap Profile identifiers
Expand Down
791 changes: 787 additions & 4 deletions CleverTapSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
4 changes: 3 additions & 1 deletion CleverTapSDK/CTConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@ extern NSString *const kCTNotifViewedApiDomain;
#define CLTAP_GEOFENCES_DID_UPDATE_NOTIFICATION @"CleverTapGeofencesDidUpdateNotification"

// valid profile identifier keys
#define CLTAP_PROFILE_IDENTIFIER_KEYS @[@"Identity", @"Email", @"FBID", @"GPID"]
#define CLTAP_PROFILE_IDENTIFIER_KEYS @[@"Identity", @"Email"] // LEGACY KEYS
#define CLTAP_ALL_PROFILE_IDENTIFIER_KEYS @[@"Identity", @"Email", @"Phone"]


17 changes: 17 additions & 0 deletions CleverTapSDK/CTFlexibleIdentityRepo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CTFlexibleIdentityRepo.h
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CTIdentityRepo.h"
#import "CleverTapInstanceConfig.h"
#import "CTDeviceInfo.h"
#import "CTValidationResultStack.h"

@interface CTFlexibleIdentityRepo : NSObject<CTIdentityRepo>
- (instancetype)initWithConfig:(CleverTapInstanceConfig*)config deviceInfo:(CTDeviceInfo*)deviceInfo validationResultStack:(CTValidationResultStack*)validationResultStack;
@end
98 changes: 98 additions & 0 deletions CleverTapSDK/CTFlexibleIdentityRepo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// CTFlexibleIdentityRepo.m
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import "CTFlexibleIdentityRepo.h"
#import "CTConstants.h"
#import "CTLoginInfoProvider.h"
#import "CleverTapInstanceConfigPrivate.h"


@interface CTFlexibleIdentityRepo () {}
@property (nonatomic, strong) NSArray *identities;
@property (nonatomic, strong) CleverTapInstanceConfig *config;
@property (nonatomic, strong) CTDeviceInfo *deviceInfo;
@property (nonatomic, strong) CTValidationResultStack *validationResultStack;
@property (nonatomic, strong) CTLoginInfoProvider *loginInfoProvider;
@end

@implementation CTFlexibleIdentityRepo

- (instancetype)initWithConfig:(CleverTapInstanceConfig*)config deviceInfo:(CTDeviceInfo*)deviceInfo validationResultStack:(CTValidationResultStack*)validationResultStack
{
self = [super init];
if (self) {
self.config = config;
self.deviceInfo = deviceInfo;
self.validationResultStack = validationResultStack;
self.loginInfoProvider = [[CTLoginInfoProvider alloc]initWithDeviceInfo:deviceInfo config:config];
[self loadIdentities];
}
return self;
}

- (NSArray *)getIdentities {
return self.identities;
}

- (BOOL)isIdentity:(NSString *)key {
return [self.identities containsObject:key];
}

- (void)loadIdentities {
// CHECK IF ITS A LEGACY USER
NSString *cachedIdentities = [self.loginInfoProvider getCachedIdentities];
NSArray *finalIdentityKeys;

// NEW USER
// GET IDENTIFIERS FROM PLIST IF DEFAULT INSTANCE ELSE CONFIG SETTER
NSArray *configIdentifiers = [self getConfigIdentifiers];

// RAISE ERROR IF CACHED AND PLIST IDENTITIES ARE NOT EQUAL
NSArray *cachedIdentityKeys = [cachedIdentities componentsSeparatedByString: @","];
if (cachedIdentityKeys.count > 0 && ![cachedIdentityKeys isEqualToArray: configIdentifiers]) {
CTValidationResult *error = [[CTValidationResult alloc] init];
NSString *errString = @"Profile Identifiers mismatch with the previously saved ones";
[error setErrorCode:531];
[error setErrorDesc:errString];
[self.validationResultStack pushValidationResult:error];
CleverTapLogDebug(self.config.logLevel, @"%@: %@", self, errString);
}

// USE CACHED IDENTITIES IF AVAILABLE, ELSE USE PLIST/SETTER, ELSE USE DEFAULT CONSTANTS
if (cachedIdentityKeys && cachedIdentityKeys.count > 0) {
finalIdentityKeys = cachedIdentityKeys;
}
else if (configIdentifiers && configIdentifiers.count > 0) {
finalIdentityKeys = configIdentifiers;
}
else {
finalIdentityKeys = CLTAP_PROFILE_IDENTIFIER_KEYS;
}

// SAVE IDENTITIES TO CACHE IF NOT ALREADY
if (!cachedIdentityKeys || cachedIdentityKeys.count == 0) {
[self.loginInfoProvider setCachedIdentities: [configIdentifiers componentsJoinedByString: @","]];
}
self.identities = finalIdentityKeys;
}

- (NSArray *)getConfigIdentifiers {
// IF DEFAULT INSTANCE, GET KEYS FROM PLIST, ELSE GET FROM SETTER
if (self.config.isDefaultInstance) {
// ONLY ADD SUPPORTED KEYS
NSArray *clevertapIdentifiers = [[NSBundle mainBundle].infoDictionary objectForKey:@"CleverTapIdentifiers"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self IN %@", CLTAP_ALL_PROFILE_IDENTIFIER_KEYS];
NSArray *result = [clevertapIdentifiers filteredArrayUsingPredicate:predicate];
return result;
}
else {
return self.config.identityKeys;
}
}

@end
15 changes: 15 additions & 0 deletions CleverTapSDK/CTIdentityRepo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CTIdentityRepo.h
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol CTIdentityRepo <NSObject>

- (NSArray*)getIdentities;
- (BOOL)isIdentity: (NSString*)key;
@end
19 changes: 19 additions & 0 deletions CleverTapSDK/CTIdentityRepoFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CTIdentityRepoFactory.h
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CTIdentityRepo.h"
#import "CleverTapInstanceConfig.h"
#import "CTDeviceInfo.h"
#import "CTValidationResultStack.h"

@interface CTIdentityRepoFactory : NSObject

+ (id<CTIdentityRepo>)getRepoForConfig:(CleverTapInstanceConfig*)config deviceInfo:(CTDeviceInfo*)deviceInfo validationResultStack:(CTValidationResultStack*)validationResultStack;

@end
29 changes: 29 additions & 0 deletions CleverTapSDK/CTIdentityRepoFactory.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// CTIdentityRepoFactory.m
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import "CTIdentityRepoFactory.h"
#import "CTLoginInfoProvider.h"
#import "CTLegacyIdentityRepo.h"
#import "CTFlexibleIdentityRepo.h"

@implementation CTIdentityRepoFactory

+ (id<CTIdentityRepo>)getRepoForConfig:(CleverTapInstanceConfig*)config deviceInfo:(CTDeviceInfo*)deviceInfo validationResultStack:(CTValidationResultStack*)validationResultStack {

id<CTIdentityRepo> identityRepo;
CTLoginInfoProvider *loginInfoProvider = [[CTLoginInfoProvider alloc]initWithDeviceInfo:deviceInfo config:config];
if ([loginInfoProvider isLegacyProfileLoggedIn]) {
identityRepo = [[CTLegacyIdentityRepo alloc]init];
}
else {
identityRepo = [[CTFlexibleIdentityRepo alloc]initWithConfig:config deviceInfo:deviceInfo validationResultStack:validationResultStack];
}
return identityRepo;
}

@end
14 changes: 14 additions & 0 deletions CleverTapSDK/CTLegacyIdentityRepo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// CTLegacyIdentityRepo.h
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CTIdentityRepo.h"

@interface CTLegacyIdentityRepo : NSObject<CTIdentityRepo>

@end
35 changes: 35 additions & 0 deletions CleverTapSDK/CTLegacyIdentityRepo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// CTLegacyIdentityRepo.m
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import "CTLegacyIdentityRepo.h"
#import "CTConstants.h"

@interface CTLegacyIdentityRepo () {}
@property (nonatomic, strong) NSArray *identities;
@end

@implementation CTLegacyIdentityRepo

- (instancetype)init
{
self = [super init];
if (self) {
self.identities = CLTAP_PROFILE_IDENTIFIER_KEYS;
}
return self;
}

- (NSArray *)getIdentities {
return self.identities;
}

- (BOOL)isIdentity:(NSString *)key {
return [self.identities containsObject:key];
}

@end
26 changes: 26 additions & 0 deletions CleverTapSDK/CTLoginInfoProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// CTLoginInfoProvider.h
// CleverTapSDK
//
// Created by Akash Malhotra on 05/12/21.
// Copyright © 2021 CleverTap. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CTDeviceInfo.h"
#import "CleverTapInstanceConfig.h"

@interface CTLoginInfoProvider : NSObject

- (void)cacheGUID:(NSString *)guid forKey:(NSString *)key andIdentifier:(NSString *)identifier;
- (BOOL)deviceIsMultiUser;
- (NSDictionary *)getCachedGUIDs;
- (void)setCachedGUIDs:(NSDictionary *)cache;
- (NSString *)getCachedIdentities;
- (NSString *)getGUIDforKey:(NSString *)key andIdentifier:(NSString *)identifier;
- (BOOL)isAnonymousDevice;
- (BOOL)isLegacyProfileLoggedIn;
- (void)setCachedIdentities:(NSString *)cache;
- (instancetype)initWithDeviceInfo:(CTDeviceInfo*)deviceInfo config:(CleverTapInstanceConfig*)config;

@end
Loading

0 comments on commit e962c9d

Please sign in to comment.