Skip to content

Commit 6ec7b3b

Browse files
[release] 0.36.0
1 parent 1aad59a commit 6ec7b3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+754
-2923
lines changed

Branch-SDK/BNCAppGroupsData.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// BNCAppGroupsData.h
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 9/27/20.
6+
// Copyright © 2020 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface BNCAppGroupsData : NSObject
14+
15+
// app group used to share data between the App Clip and the Full App
16+
@property (nonatomic, strong, readwrite) NSString *appGroup;
17+
18+
// App Clip data
19+
@property (nonatomic, strong, readwrite) NSString *bundleID;
20+
@property (nonatomic, strong, readwrite) NSDate *installDate;
21+
@property (nonatomic, strong, readwrite) NSString *url;
22+
@property (nonatomic, strong, readwrite) NSString *branchToken;
23+
@property (nonatomic, strong, readwrite) NSString *bundleToken;
24+
25+
+ (instancetype)shared;
26+
27+
// saves app clip data when appropriate
28+
- (void)saveAppClipData;
29+
30+
// loads app clip data
31+
- (BOOL)loadAppClipData;
32+
33+
@end
34+
35+
NS_ASSUME_NONNULL_END

Branch-SDK/BNCAppGroupsData.m

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// BNCAppGroupsData.m
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 9/27/20.
6+
// Copyright © 2020 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "BNCAppGroupsData.h"
10+
11+
#import "BNCLog.h"
12+
#import "BNCDeviceInfo.h"
13+
#import "BNCApplication.h"
14+
#import "BNCPreferenceHelper.h"
15+
16+
@interface BNCAppGroupsData()
17+
@property (nonatomic, strong, readwrite) NSUserDefaults *groupDefaults;
18+
@end
19+
20+
@implementation BNCAppGroupsData
21+
22+
+ (instancetype)shared {
23+
static BNCAppGroupsData *appGroupsData;
24+
static dispatch_once_t onceToken;
25+
dispatch_once(&onceToken, ^{
26+
appGroupsData = [BNCAppGroupsData new];
27+
});
28+
return appGroupsData;
29+
}
30+
31+
// lazy load the App Group NSUserDefaults
32+
- (BOOL)appGroupsAvailable {
33+
if (!self.groupDefaults && self.appGroup) {
34+
self.groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:self.appGroup];
35+
}
36+
37+
if (self.groupDefaults) {
38+
return YES;
39+
} else {
40+
return NO;
41+
}
42+
}
43+
44+
- (void)saveObject:(NSObject *)obj forKey:(NSString *)key {
45+
if ([self appGroupsAvailable] && obj) {
46+
[self.groupDefaults setObject:obj forKey:key];
47+
}
48+
}
49+
50+
- (NSString *)getStringForKey:(NSString *)key {
51+
if ([self appGroupsAvailable]) {
52+
return [self.groupDefaults stringForKey:key];
53+
}
54+
return nil;
55+
}
56+
57+
- (NSDate *)getDateForKey:(NSString *)key {
58+
if ([self appGroupsAvailable]) {
59+
id date = [self.groupDefaults objectForKey:key];
60+
if ([date isKindOfClass:NSDate.class]) {
61+
return (NSDate *)date;
62+
} else {
63+
return nil;
64+
}
65+
}
66+
return nil;
67+
}
68+
69+
- (void)saveAppClipData {
70+
BNCDeviceInfo *deviceInfo = [BNCDeviceInfo getInstance];
71+
if ([deviceInfo isAppClip]) {
72+
73+
BNCApplication *application = [BNCApplication currentApplication];
74+
75+
// bundle id - sanity check that data isn't coming cross app
76+
// this should never happen as we only save from an App Clip
77+
NSString *bundleId = application.bundleID;
78+
NSDate *installDate = application.firstInstallDate;
79+
80+
[self saveObject:bundleId forKey:@"BranchAppClipBundleId"];
81+
[self saveObject:installDate forKey:@"BranchAppClipFirstInstallDate"];
82+
83+
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
84+
85+
NSString *url = preferenceHelper.referringURL;
86+
NSString *token = preferenceHelper.deviceFingerprintID;
87+
NSString *bundleToken = preferenceHelper.identityID;
88+
89+
[self saveObject:url forKey:@"BranchAppClipURL"];
90+
[self saveObject:token forKey:@"BranchAppClipToken"];
91+
[self saveObject:bundleToken forKey:@"BranchAppClipBundleToken"];
92+
93+
NSString *logMessage = [NSString stringWithFormat:@"Saving App Clip Data: %@, %@, %@, %@, %@", bundleId, installDate, url, token, bundleToken];
94+
BNCLogDebug(logMessage);
95+
}
96+
}
97+
98+
- (BOOL)loadAppClipData {
99+
BNCDeviceInfo *deviceInfo = [BNCDeviceInfo getInstance];
100+
if (![deviceInfo isAppClip]) {
101+
102+
self.bundleID = [self getStringForKey:@"BranchAppClipBundleId"];
103+
self.installDate = [self getDateForKey:@"BranchAppClipFirstInstallDate"];
104+
self.url = [self getStringForKey:@"BranchAppClipURL"];
105+
self.branchToken = [self getStringForKey:@"BranchAppClipToken"];
106+
self.bundleToken = [self getStringForKey:@"BranchAppClipBundleToken"];
107+
108+
if (self.bundleID && self.installDate && self.url && self.branchToken && self.bundleToken) {
109+
NSString *logMessage = [NSString stringWithFormat:@"Loading App Clip Data: %@, %@, %@, %@, %@", self.bundleID, self.installDate, self.url, self.branchToken, self.bundleToken];
110+
BNCLogDebug(logMessage);
111+
112+
return YES;
113+
} else {
114+
return NO;
115+
}
116+
}
117+
return NO;
118+
}
119+
120+
@end

Branch-SDK/BNCApplication.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ + (NSDate*) currentBuildDate {
8888
NSFileManager *fileManager = [NSFileManager defaultManager];
8989
NSDictionary *attributes = [fileManager attributesOfItemAtPath:appURL.path error:&error];
9090
if (error) {
91-
BNCLogError(@"Can't get build date: %@.", error);
91+
BNCLogError([NSString stringWithFormat:@"Can't get build date: %@.", error]);
9292
return nil;
9393
}
9494
NSDate * buildDate = [attributes fileCreationDate];
9595
if (buildDate == nil || [buildDate timeIntervalSince1970] <= 0.0) {
96-
BNCLogError(@"Invalid build date: %@.", buildDate);
96+
BNCLogError([NSString stringWithFormat:@"Invalid build date: %@.", buildDate]);
9797
}
9898
return buildDate;
9999
}
@@ -112,7 +112,7 @@ + (NSDate*) firstInstallBuildDate {
112112
forService:kBranchKeychainService
113113
key:kBranchKeychainFirstBuildKey
114114
cloudAccessGroup:nil];
115-
if (error) BNCLogError(@"Keychain store: %@.", error);
115+
if (error) BNCLogError([NSString stringWithFormat:@"Keychain store: %@.", error]);
116116
return firstBuildDate;
117117
}
118118

@@ -125,7 +125,7 @@ + (NSDate *) currentInstallDate {
125125
#endif
126126

127127
if (installDate == nil || [installDate timeIntervalSince1970] <= 0.0) {
128-
BNCLogWarning(@"Invalid install date, using [NSDate date].");
128+
BNCLogWarning([NSString stringWithFormat:@"Invalid install date, using [NSDate date]."]);
129129
}
130130
return installDate;
131131
}
@@ -136,7 +136,7 @@ + (NSDate *)creationDateForLibraryDirectory {
136136
NSURL *directoryURL = [[fileManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] firstObject];
137137
NSDictionary *attributes = [fileManager attributesOfItemAtPath:directoryURL.path error:&error];
138138
if (error) {
139-
BNCLogError(@"Can't get creation date for Library directory: %@", error);
139+
BNCLogError([NSString stringWithFormat:@"Can't get creation date for Library directory: %@", error]);
140140
return nil;
141141
}
142142
return [attributes fileCreationDate];
@@ -156,7 +156,7 @@ + (NSDate*) firstInstallDate {
156156
// save filesystem time to keychain
157157
error = [BNCKeyChain storeValue:firstInstallDate forService:kBranchKeychainService key:kBranchKeychainFirstInstalldKey cloudAccessGroup:nil];
158158
if (error) {
159-
BNCLogError(@"Keychain store: %@.", error);
159+
BNCLogError([NSString stringWithFormat:@"Keychain store: %@.", error]);
160160
}
161161
return firstInstallDate;
162162
}
@@ -168,7 +168,7 @@ - (NSDictionary*) deviceKeyIdentityValueDictionary {
168168
[BNCKeyChain retrieveValueForService:kBranchKeychainService
169169
key:kBranchKeychainDevicesKey
170170
error:&error];
171-
if (error) BNCLogWarning(@"While retrieving deviceKeyIdentityValueDictionary: %@.", error);
171+
if (error) BNCLogWarning([NSString stringWithFormat:@"While retrieving deviceKeyIdentityValueDictionary: %@.", error]);
172172
if (!deviceDictionary) deviceDictionary = @{};
173173
return deviceDictionary;
174174
}

Branch-SDK/BNCConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
NSString * const BNC_API_BASE_URL = @"https://api2.branch.io";
1212
NSString * const BNC_API_VERSION = @"v1";
1313
NSString * const BNC_LINK_URL = @"https://bnc.lt";
14-
NSString * const BNC_SDK_VERSION = @"0.35.1";
14+
NSString * const BNC_SDK_VERSION = @"0.36.0";

Branch-SDK/BNCDebug.h

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)