Skip to content

Commit 2227634

Browse files
authored
Flattened the BUO like on Android. (#771)
1 parent b563c5a commit 2227634

File tree

10 files changed

+142
-27
lines changed

10 files changed

+142
-27
lines changed

Branch-SDK/Branch-SDK/BNCFieldDefines.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@
101101
} \
102102
} \
103103
object.field = newArray; \
104+
} else if ([a isKindOfClass:[NSString class]]) { \
105+
object.field = [NSMutableArray arrayWithObject:a]; \
104106
} else { \
105-
object.field = (id) [NSArray new]; \
107+
object.field = (id) [NSMutableArray new]; \
106108
} \
107109
}
108110

Branch-SDK/Branch-SDK/BranchUniversalObject.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ FOUNDATION_EXPORT BranchCondition _Nonnull BranchConditionRefurbished;
184184
andCallback:(void (^_Nullable)(NSString * _Nullable url, NSError * _Nullable error))callback;
185185

186186
/// Returns a Branch long URL to the content item
187-
- (nullable NSString *)getLongUrlWithChannel:(nullable NSString *)channel andTags:(nullable NSArray *)tags andFeature:(nullable NSString *)feature andStage:(nullable NSString *)stage andAlias:(nullable NSString *)alia;
187+
- (nullable NSString *)getLongUrlWithChannel:(nullable NSString *)channel
188+
andTags:(nullable NSArray *)tags
189+
andFeature:(nullable NSString *)feature
190+
andStage:(nullable NSString *)stage
191+
andAlias:(nullable NSString *)alias;
188192

189193
/// @name Share Sheet Handling
190194

Branch-SDK/Branch-SDK/BranchUniversalObject.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ @implementation BranchContentMetadata
6767
- (NSDictionary*_Nonnull) dictionary {
6868
NSMutableDictionary*dictionary = [NSMutableDictionary new];
6969

70+
for (NSString *key in self.customMetadata.keyEnumerator) {
71+
NSString *value = self.customMetadata[key];
72+
dictionary[key] = value;
73+
}
74+
7075
#define BNCFieldDefinesDictionaryFromSelf
7176
#include "BNCFieldDefines.h"
7277

@@ -91,7 +96,6 @@ - (NSDictionary*_Nonnull) dictionary {
9196
addDouble(latitude, $latitude);
9297
addDouble(longitude, $longitude);
9398
addStringArray(imageCaptions,$image_captions);
94-
addStringifiedDictionary(customMetadata, $custom_fields);
9599

96100
#include "BNCFieldDefines.h"
97101

@@ -126,7 +130,6 @@ + (BranchContentMetadata*_Nonnull) contentMetadataWithDictionary:(NSDictionary*_
126130
addDouble(latitude, $latitude);
127131
addDouble(longitude, $longitude);
128132
addStringArray(imageCaptions,$image_captions);
129-
addStringifiedDictionary(customMetadata, $custom_fields);
130133

131134
#include "BNCFieldDefines.h"
132135

Branch-TestBed-Swift/TestBed-Swift.xcodeproj/project.pbxproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@
674674
"${PODS_ROOT}/Amplitude-iOS/Amplitude/ComodoCaLimitedRsaCertificationAuthority.der",
675675
"${PODS_ROOT}/Amplitude-iOS/Amplitude/ComodoRsaCA.der",
676676
"${PODS_ROOT}/Amplitude-iOS/Amplitude/ComodoRsaDomainValidationCA.der",
677-
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyKit/Appboy.bundle",
678677
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/ABKFeedbackViewController/Feedback_Resources/ABKModalFeedbackViewController.xib",
679678
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/ABKFeedbackViewController/Feedback_Resources/ABKNavigationFeedbackViewController.xib",
680679
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/ABKFeedbackViewController/Feedback_Resources/ar.lproj/AppboyFeedbackLocalizable.strings",
@@ -753,6 +752,18 @@
753752
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/ABKFeedbackViewController/Feedback_Resources/zh-HK.lproj",
754753
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/ABKFeedbackViewController/Feedback_Resources/zh-TW.lproj",
755754
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/ABKFeedbackViewController/Feedback_Resources/zh.lproj",
755+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/ABKInAppMessageFullViewController.xib",
756+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/ABKInAppMessageHTMLFullViewController.xib",
757+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/ABKInAppMessageModalViewController.xib",
758+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/ABKInAppMessageSlideupViewController.xib",
759+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/arrow.png",
760+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/[email protected]",
761+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/com_appboy_inapp_close_icon.png",
762+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/[email protected]",
763+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/[email protected]",
764+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/FontAwesome.otf",
765+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyUI/InAppMessage/Resources/SlideupArrow.png",
766+
"${PODS_ROOT}/Appboy-iOS-SDK/AppboyKit/Appboy.bundle",
756767
"${PODS_ROOT}/Mixpanel/Mixpanel/Images/MPArrowLeft.png",
757768
"${PODS_ROOT}/Mixpanel/Mixpanel/Images/[email protected]",
758769
"${PODS_ROOT}/Mixpanel/Mixpanel/Images/MPArrowRight.png",

Branch-TestBed/Branch-SDK-Tests/BNCEncodingUtils.Test.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ - (void)testEncodeDictionaryToJsonStringWithExpectedParams {
2525
NSString *formattedDateString = [dateFormatter stringFromDate:date];
2626

2727
NSURL *someUrl = [NSURL URLWithString:@"https://branch.io"];
28-
NSDictionary *dataDict = @{ @"foo": @"bar", @"num": @1, @"array": @[ @"array", @"items" ], @"dict": @{ @"sub": @1 }, @"url": someUrl, @"date": date };
29-
NSString *expectedEncodedString = [NSString stringWithFormat:@"{\"foo\":\"bar\",\"num\":1,\"array\":[\"array\",\"items\"],\"dict\":{\"sub\":1},\"url\":\"https://branch.io\",\"date\":\"%@\"}", formattedDateString];
30-
28+
NSDictionary *dataDict = @{
29+
@"foo": @"bar",
30+
@"num": @1,
31+
@"array": @[ @"array", @"items" ],
32+
@"dict": @{ @"sub": @1 },
33+
@"url": someUrl,
34+
@"date": date
35+
};
36+
NSString *expectedEncodedString = [NSString stringWithFormat:
37+
@"{\"foo\":\"bar\",\"num\":1,\"array\":[\"array\",\"items\"],\"dict\":{\"sub\":1},\"url\":\"https://branch.io\",\"date\":\"%@\"}",
38+
formattedDateString];
3139
NSString *encodedValue = [BNCEncodingUtils encodeDictionaryToJsonString:dataDict];
3240

3341
XCTAssertEqualObjects(expectedEncodedString, encodedValue);

Branch-TestBed/Branch-SDK-Tests/Branch-SDK-Tests.strings

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Instance 0x132585f70 is of class 'DumpClass' of class 'NSObject':
9393
\"$latitude\": 12.07,
9494
\"$longitude\": -97.5,
9595
\"$image_captions\": [\"my_img_caption1\", \"my_img_caption_2\"],
96-
\"$custom_fields\": \"{\\\"Custom_Content_metadata_key1\\\":\\\"Custom_Content_metadata_val1\\\"}\",
9796
\"$og_title\": \"My Content Title\",
9897
\"$canonical_identifier\": \"item\/12345\",
9998
\"$canonical_url\": \"https:\/\/branch.io\/deepviews\",
@@ -103,7 +102,9 @@ Instance 0x132585f70 is of class 'DumpClass' of class 'NSObject':
103102
\"$exp_date\": 212123232544,
104103
\"$publicly_indexable\": false,
105104
\"$locally_indexable\": true,
106-
\"$creation_timestamp\": 1501869445321
105+
\"$creation_timestamp\": 1501869445321,
106+
\"Custom_Content_metadata_key1\": \"Custom_Content_metadata_val1\",
107+
\"Custom_Content_metadata_key2\": \"Custom_Content_metadata_val2\"
107108
}
108109
";
109110
"V2EventProperties" =
@@ -165,7 +166,8 @@ Instance 0x132585f70 is of class 'DumpClass' of class 'NSObject':
165166
\"$latitude\": 12.07,
166167
\"$longitude\": -97.5,
167168
\"$image_captions\": [\"my_img_caption1\", \"my_img_caption_2\"],
168-
\"$custom_fields\": \"{\\\"Custom_Content_metadata_key1\\\":\\\"Custom_Content_metadata_val1\\\"}\",
169+
\"Custom_Content_metadata_key1\": \"Custom_Content_metadata_val1\",
170+
\"Custom_Content_metadata_key2\": \"Custom_Content_metadata_val2\",
169171
\"$og_title\": \"My Content Title\",
170172
\"$canonical_identifier\": \"item\/12345\",
171173
\"$canonical_url\": \"https:\/\/branch.io\/deepviews\",
@@ -207,6 +209,7 @@ Instance 0x132585f70 is of class 'DumpClass' of class 'NSObject':
207209
imageUrl: https://test_img_url
208210
metadata: {
209211
\"Custom_Content_metadata_key1\" = \"Custom_Content_metadata_val1\";
212+
\"Custom_Content_metadata_key2\" = \"Custom_Content_metadata_val2\";
210213
}
211214
type: COMMERCE_PRODUCT
212215
locallyIndex: 1

Branch-TestBed/Branch-SDK-Tests/BranchDelegate.Test.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ - (void) branchDidStartSessionNotification:(NSNotification*)notification {
291291
@"$canonical_url": @"https://dev.branch.io/getting-started/deep-link-routing/guide/ios/",
292292
@"$content_type": @"some type",
293293
@"$currency": @"$",
294-
@"$custom_fields": @"{\"+click_timestamp\":1506983962,\"+clicked_branch_link\":true,\"$identity_id\":\"423237095633725879\",\"$one_time_use\":false,\"$amount\":1000,\"~feature\":\"Sharing Feature\",\"$content_type\":\"some type\",\"~creation_source\":3,\"~channel\":\"Distribution Channel\",\"~id\":423243086454504450,\"deeplink_text\":\"This text was embedded as data in a Branch link with the following characteristics:\\n\\ncanonicalUrl: https://dev.branch.io/getting-started/deep-link-routing/guide/ios/\\n title: Content Title\\n contentDescription: My Content Description\\n imageUrl: https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png\\n\",\"~referring_link\":\"https://bnctestbed.app.link/izPBY2xCqF\",\"+match_guaranteed\":true,\"$desktop_url\":\"http://branch.io\",\"+is_first_session\":false,\"$ios_url\":\"https://dev.branch.io/getting-started/sdk-integration-guide/guide/ios/\",\"~campaign\":\"some campaign\"}",
295294
@"$desktop_url": @"http://branch.io",
296295
@"$exp_date": @0,
297296
@"$identity_id": @"423237095633725879",
@@ -301,21 +300,25 @@ - (void) branchDidStartSessionNotification:(NSNotification*)notification {
301300
@"$og_title": @"Content Title",
302301
@"$one_time_use": @0,
303302
@"$publicly_indexable": @1,
303+
304+
@"+click_timestamp": @1506983962,
305+
@"+clicked_branch_link": @1,
306+
@"+is_first_session": @0,
307+
@"+match_guaranteed": @1,
308+
309+
@"deeplink_text": @"This text was embedded as data in a Branch link with the following characteristics:\n\ncanonicalUrl: https://dev.branch.io/getting-started/deep-link-routing/guide/ios/\n title: Content Title\n contentDescription: My Content Description\n imageUrl: https://pbs.twimg.com/profile_images/658759610220703744/IO1HUADP.png\n",
310+
304311
@"~campaign": @"some campaign",
305312
@"~channel": @"Distribution Channel",
313+
@"~creation_source": @3,
306314
@"~duration": @0,
307315
@"~feature": @"Sharing Feature",
316+
@"~id": @423243086454504450,
317+
@"~referring_link": @"https://bnctestbed.app.link/izPBY2xCqF"
308318
}];
309319

310-
NSDictionary *dCustom = [BNCEncodingUtils decodeJsonStringToDictionary:d[@"$custom_fields"]];
311-
d[@"$custom_fields"] = nil;
312-
313-
NSDictionary *tCustom = [BNCEncodingUtils decodeJsonStringToDictionary:truth[@"$custom_fields"]];
314-
truth[@"$custom_fields"] = nil;
315-
316320
XCTAssertTrue(d.count == truth.count);
317321
XCTAssertTrue(!d || [d isEqualToDictionary:truth]);
318-
XCTAssertTrue(!dCustom || [dCustom isEqualToDictionary:tCustom]);
319322
}
320323

321324
[self.branchDidOpenURLNotificationExpectation fulfill];

Branch-TestBed/Branch-SDK-Tests/BranchEvent.Test.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ - (void) testEvent {
7777
buo.contentMetadata.longitude = -97.5;
7878
buo.contentMetadata.imageCaptions = (id) @[@"my_img_caption1", @"my_img_caption_2"];
7979
buo.contentMetadata.customMetadata = (NSMutableDictionary*) @{
80-
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1"
80+
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1",
81+
@"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2"
8182
};
8283

8384
// Set up the event properties --
@@ -131,7 +132,7 @@ - (void) testEvent {
131132
NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:bodyData options:0 error:&error];
132133
XCTAssertNil(error);
133134

134-
NSLog(@"1");
135+
NSLog(@"testEvent 1");
135136
NSLog(@"URL: %@.", url);
136137
NSLog(@"Body: %@.", parameters);
137138

@@ -222,7 +223,8 @@ - (void) testUserCompletedAction {
222223
buo.contentMetadata.longitude = -97.5;
223224
buo.contentMetadata.imageCaptions = (id) @[@"my_img_caption1", @"my_img_caption_2"];
224225
buo.contentMetadata.customMetadata = (NSMutableDictionary*) @{
225-
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1"
226+
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1",
227+
@"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2"
226228
};
227229

228230
// Set up and invoke --

Branch-TestBed/Branch-SDK-Tests/BranchEvent.Test.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import Foundation
1010

1111
class BranchEventTestSwift : BNCTestCase {
1212

13+
override func setUp() {
14+
Branch.getInstance("key_live_foo")
15+
}
16+
1317
func testBranchEvent() {
1418

1519
// Set up the Branch Universal Object --
@@ -49,7 +53,8 @@ class BranchEventTestSwift : BNCTestCase {
4953
branchUniversalObject.contentMetadata.longitude = -97.5
5054
branchUniversalObject.contentMetadata.imageCaptions = [ "my_img_caption1", "my_img_caption_2"]
5155
branchUniversalObject.contentMetadata.customMetadata = [
52-
"Custom_Content_metadata_key1": "Custom_Content_metadata_val1"
56+
"Custom_Content_metadata_key1": "Custom_Content_metadata_val1",
57+
"Custom_Content_metadata_key2": "Custom_Content_metadata_val2"
5358
]
5459

5560
// Set up the event properties --
@@ -97,5 +102,16 @@ class BranchEventTestSwift : BNCTestCase {
97102
event.logEvent()
98103

99104
event = BranchEvent.standardEvent(.viewItem)
105+
event.logEvent();
106+
107+
// Quickly log an event:
108+
BranchEvent.standardEvent(.viewItem).logEvent()
109+
110+
// Quickly log an event with content:
111+
let branchUniversalObject = BranchUniversalObject.init()
112+
branchUniversalObject.canonicalIdentifier = "item/12345"
113+
branchUniversalObject.canonicalUrl = "https://branch.io/deepviews"
114+
branchUniversalObject.title = "My Content Title"
115+
BranchEvent.standardEvent(.viewItem, withContentItem: branchUniversalObject).logEvent()
100116
}
101117
}

Branch-TestBed/Branch-SDK-Tests/BranchUniversalObject.Test.m

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ - (void) testDeserialize {
5454
XCTAssertEqual(buo.contentMetadata.longitude, -97.5);
5555
NSArray *array = @[@"my_img_caption1", @"my_img_caption_2"];
5656
XCTAssertEqualObjects(buo.contentMetadata.imageCaptions, array);
57-
XCTAssertEqualObjects(buo.contentMetadata.customMetadata,
58-
@{@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1"});
57+
NSDictionary *d = @{
58+
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1",
59+
@"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2"
60+
};
61+
XCTAssertEqualObjects(buo.contentMetadata.customMetadata, d);
5962
XCTAssertEqualObjects(buo.title, @"My Content Title");
6063
XCTAssertEqualObjects(buo.canonicalIdentifier, @"item/12345");
6164
XCTAssertEqualObjects(buo.canonicalUrl, @"https://branch.io/deepviews");
@@ -85,16 +88,76 @@ - (void) testDeserialize {
8588
XCTAssert(data);
8689

8790
// NSString *newString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
88-
// Can't compare strings since the item order may be different.
91+
// Can't compare strings since the field item order may be different.
8992
// XCTAssertEqualObjects(jsonString, newString);
9093
}
9194

95+
- (void) testSerialize {
96+
BranchUniversalObject *buo = [BranchUniversalObject new];
97+
buo.contentMetadata.contentSchema = BranchContentSchemaCommerceProduct;
98+
buo.contentMetadata.quantity = 2;
99+
buo.contentMetadata.price = [NSDecimalNumber decimalNumberWithString:@"23.20"];
100+
buo.contentMetadata.currency = BNCCurrencyUSD;
101+
buo.contentMetadata.sku = @"1994320302";
102+
buo.contentMetadata.productName = @"my_product_name1";
103+
buo.contentMetadata.productBrand = @"my_prod_Brand1";
104+
buo.contentMetadata.productCategory = BNCProductCategoryBabyToddler;
105+
buo.contentMetadata.productVariant = @"3T";
106+
buo.contentMetadata.condition = @"FAIR";
107+
buo.contentMetadata.ratingAverage = 5;
108+
buo.contentMetadata.ratingCount = 5;
109+
buo.contentMetadata.ratingMax = 7;
110+
buo.contentMetadata.addressStreet = @"Street_name1";
111+
buo.contentMetadata.addressCity = @"city1";
112+
buo.contentMetadata.addressRegion = @"Region1";
113+
buo.contentMetadata.addressCountry = @"Country1";
114+
buo.contentMetadata.addressPostalCode = @"postal_code";
115+
buo.contentMetadata.latitude = 12.07;
116+
buo.contentMetadata.longitude = -97.5;
117+
buo.contentMetadata.imageCaptions = (id) @[@"my_img_caption1", @"my_img_caption_2"];
118+
buo.contentMetadata.customMetadata = (id) @{
119+
@"Custom_Content_metadata_key1": @"Custom_Content_metadata_val1",
120+
@"Custom_Content_metadata_key2": @"Custom_Content_metadata_val2"
121+
};
122+
buo.title = @"My Content Title";
123+
buo.canonicalIdentifier = @"item/12345";
124+
buo.canonicalUrl = @"https://branch.io/deepviews";
125+
buo.keywords = @[@"My_Keyword1", @"My_Keyword2"];
126+
buo.contentDescription = @"my_product_description1";
127+
buo.imageUrl = @"https://test_img_url";
128+
buo.expirationDate = [NSDate dateWithTimeIntervalSince1970:(double)212123232544.0/1000.0];
129+
buo.publiclyIndex = NO;
130+
buo.locallyIndex = YES;
131+
buo.creationDate = [NSDate dateWithTimeIntervalSince1970:(double)1501869445321.0/1000.0];
132+
133+
NSDictionary *buoDictionary = buo.dictionary;
134+
135+
// Load the JSON:
136+
137+
NSString *jsonString = [self stringFromBundleWithKey:@"BranchUniversalObjectJSON"];
138+
XCTAssertTrue(jsonString, @"Can't load BranchUniversalObjectJSON resource from plist!");
139+
140+
NSError *error = nil;
141+
NSMutableDictionary *jsonDictionary =
142+
[[NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]
143+
options:0 error:&error]
144+
mutableCopy];
145+
XCTAssertNil(error);
146+
jsonDictionary[@"$publicly_indexable"] = nil;
147+
148+
// Compare:
149+
150+
XCTAssert(buoDictionary);
151+
XCTAssert(jsonDictionary);
152+
XCTAssertEqualObjects(buoDictionary, jsonDictionary);
153+
}
154+
92155
- (void) testSchemaDescription {
93156
NSDictionary *d = [self mutableDictionaryFromBundleJSONWithKey:@"BranchUniversalObjectJSON"];
94157
BranchUniversalObject *b = [BranchUniversalObject objectWithDictionary:d];
95158
NSString *s = b.contentMetadata.description;
96159
BNCTAssertEqualMaskedString(s,
97-
@"<BranchContentMetadata 0x**************** schema: COMMERCE_PRODUCT userData: 1 items>");
160+
@"<BranchContentMetadata 0x**************** schema: COMMERCE_PRODUCT userData: 2 items>");
98161
}
99162

100163
- (void) testBUODescription {

0 commit comments

Comments
 (0)