@@ -305,7 +305,7 @@ - (void)userCompletedAction:(NSString *)action withState:(NSDictionary *)state {
305305 [[BranchEvent customEventWithName: action contentItem: self ] logEvent ];
306306
307307 // Maybe list on spotlight --
308- NSDictionary *linkParams = [ self getParamsForServerRequest ] ;
308+ NSDictionary *linkParams = self. dictionary ;
309309 if (self.locallyIndex && self.canonicalIdentifier && linkParams) {
310310
311311 NSMutableDictionary *actionPayload = [[NSMutableDictionary alloc ] init ];
@@ -377,8 +377,20 @@ - (NSString *)getShortUrlWithLinkPropertiesAndIgnoreFirstClick:(BranchLinkProper
377377 forceLinkCreation: YES ];
378378}
379379
380- - (NSString *)getLongUrlWithChannel : (NSString *)channel andTags : (NSArray *)tags andFeature : (NSString *)feature andStage : (NSString *)stage andAlias : (NSString *)alia {
381- return [[Branch getInstance ] getLongURLWithParams: [self getParamsForServerRequest ] andChannel: channel andTags: tags andFeature: feature andStage: stage andAlias: alia];
380+ - (NSString *)getLongUrlWithChannel : (NSString *)channel
381+ andTags : (NSArray *)tags
382+ andFeature : (NSString *)feature
383+ andStage : (NSString *)stage
384+ andAlias : (NSString *)alias {
385+ NSString *urlString =
386+ [[Branch getInstance ]
387+ getLongURLWithParams: self .dictionary
388+ andChannel: channel
389+ andTags: tags
390+ andFeature: feature
391+ andStage: stage
392+ andAlias: alias];
393+ return urlString;
382394}
383395
384396#pragma mark - Share Sheets
@@ -596,85 +608,13 @@ - (void) removeFromSpotlightWithCallback:(void (^_Nullable)(NSError * _Nullable
596608 }
597609}
598610
599- #pragma mark - Private methods
600611#pragma mark - Dictionary Methods
601612
602- + (BranchUniversalObject *)getBranchUniversalObjectFromDictionary : (NSDictionary *)dictionary {
603- BranchUniversalObject *universalObject = [[BranchUniversalObject alloc ] init ];
604-
605- // Build BranchUniversalObject base properties
606- universalObject.contentMetadata .customMetadata = [dictionary copy ];
607- if (dictionary[BRANCH_LINK_DATA_KEY_CANONICAL_IDENTIFIER]) {
608- universalObject.canonicalIdentifier = dictionary[BRANCH_LINK_DATA_KEY_CANONICAL_IDENTIFIER];
609- }
610- if (dictionary[BRANCH_LINK_DATA_KEY_CANONICAL_URL]) {
611- universalObject.canonicalUrl = dictionary[BRANCH_LINK_DATA_KEY_CANONICAL_URL];
612- }
613- if (dictionary[BRANCH_LINK_DATA_KEY_OG_TITLE]) {
614- universalObject.title = dictionary[BRANCH_LINK_DATA_KEY_OG_TITLE];
615- }
616- if (dictionary[BRANCH_LINK_DATA_KEY_OG_DESCRIPTION]) {
617- universalObject.contentDescription = dictionary[BRANCH_LINK_DATA_KEY_OG_DESCRIPTION];
618- }
619- if (dictionary[BRANCH_LINK_DATA_KEY_OG_IMAGE_URL]) {
620- universalObject.imageUrl = dictionary[BRANCH_LINK_DATA_KEY_OG_IMAGE_URL];
621- }
622- universalObject.publiclyIndex = [dictionary[BRANCH_LINK_DATA_KEY_PUBLICLY_INDEXABLE] boolValue ];
623- universalObject.locallyIndex = [dictionary[BRANCH_LINK_DATA_KEY_LOCALLY_INDEXABLE] boolValue ];
624-
625- NSNumber *number = dictionary[BRANCH_LINK_DATA_KEY_CONTENT_EXPIRATION_DATE];
626- if ([number isKindOfClass: [NSNumber class ]]) {
627- // Number is millisecondsSince1970
628- universalObject.expirationDate = [NSDate dateWithTimeIntervalSince1970: number.integerValue/1000 ];
629- }
630- if (dictionary[BRANCH_LINK_DATA_KEY_KEYWORDS]) {
631- universalObject.keywords = dictionary[BRANCH_LINK_DATA_KEY_KEYWORDS];
632- }
633- NSString *s = dictionary[BNCPurchaseAmount];
634- if (s) {
635- if ([s isKindOfClass: NSString .class])
636- universalObject.contentMetadata .price = [NSDecimalNumber decimalNumberWithString: s];
637- else
638- if ([s isKindOfClass: NSDecimalNumber .class])
639- universalObject.contentMetadata .price = (NSDecimalNumber *) s;
640- else
641- if ([s isKindOfClass: NSNumber .class]) {
642- s = [((NSNumber *)s) stringValue ];
643- universalObject.contentMetadata .price = [NSDecimalNumber decimalNumberWithString: s];
644- }
645- }
646- if (dictionary[BNCPurchaseCurrency]) {
647- universalObject.contentMetadata .currency = dictionary[BNCPurchaseCurrency];
648- }
649-
650- if (dictionary[BRANCH_LINK_DATA_KEY_CONTENT_TYPE]) {
651- universalObject.contentMetadata .contentSchema = dictionary[BRANCH_LINK_DATA_KEY_CONTENT_TYPE];
652- }
653- return universalObject;
654- }
655-
656- - (NSDictionary *_Nonnull) getParamsForServerRequest {
657- NSMutableDictionary *temp = [[NSMutableDictionary alloc ] init ];
658- [self safeSetValue: self .canonicalIdentifier forKey: BRANCH_LINK_DATA_KEY_CANONICAL_IDENTIFIER onDict: temp];
659- [self safeSetValue: self .canonicalUrl forKey: BRANCH_LINK_DATA_KEY_CANONICAL_URL onDict: temp];
660- [self safeSetValue: self .title forKey: BRANCH_LINK_DATA_KEY_OG_TITLE onDict: temp];
661- [self safeSetValue: self .contentDescription forKey: BRANCH_LINK_DATA_KEY_OG_DESCRIPTION onDict: temp];
662- [self safeSetValue: self .imageUrl forKey: BRANCH_LINK_DATA_KEY_OG_IMAGE_URL onDict: temp];
663- temp[BRANCH_LINK_DATA_KEY_PUBLICLY_INDEXABLE] = [NSNumber numberWithBool: self .publiclyIndex];
664- temp[BRANCH_LINK_DATA_KEY_LOCALLY_INDEXABLE] = [NSNumber numberWithBool: self .locallyIndex];
665- [self safeSetValue: self .keywords forKey: BRANCH_LINK_DATA_KEY_KEYWORDS onDict: temp];
666- [self safeSetValue: @(1000 * [self .expirationDate timeIntervalSince1970 ]) forKey: BRANCH_LINK_DATA_KEY_CONTENT_EXPIRATION_DATE onDict: temp];
667- [self safeSetValue: self .contentMetadata.contentSchema forKey: BRANCH_LINK_DATA_KEY_CONTENT_TYPE onDict: temp];
668- [self safeSetValue: self .contentMetadata.currency forKey: BNCPurchaseCurrency onDict: temp];
669- temp[BNCPurchaseAmount] = self.contentMetadata .price ;
670- [temp addEntriesFromDictionary: [self .contentMetadata.customMetadata copy ]];
671- return [temp copy ];
672- }
673-
674613- (NSDictionary *)getParamsForServerRequestWithAddedLinkProperties : (BranchLinkProperties *)linkProperties {
675- NSMutableDictionary *temp = [[self getParamsForServerRequest ] mutableCopy ];
676- [temp addEntriesFromDictionary: [linkProperties.controlParams copy ]]; // TODO: Add warnings if controlParams contains non-control params
677- return [temp copy ];
614+ // TODO: Add warnings if controlParams contains non-control params
615+ NSMutableDictionary *temp = self.dictionary ;
616+ [temp addEntriesFromDictionary: [linkProperties.controlParams copy ]];
617+ return temp;
678618}
679619
680620- (NSDictionary *)getDictionaryWithCompleteLinkProperties : (BranchLinkProperties *)linkProperties {
@@ -717,14 +657,60 @@ + (BranchUniversalObject*_Nonnull) objectWithDictionary:(NSDictionary*_Null_unsp
717657
718658 BranchContentMetadata *data = [BranchContentMetadata contentMetadataWithDictionary: dictionary];
719659 object.contentMetadata = data;
720-
660+
661+ NSSet *fieldsAdded = [NSSet setWithArray: @[
662+ @" $canonical_identifier" ,
663+ @" $canonical_url" ,
664+ @" $creation_timestamp" ,
665+ @" $exp_date" ,
666+ @" $keywords" ,
667+ @" $locally_indexable" ,
668+ @" $og_description" ,
669+ @" $og_image_url" ,
670+ @" $og_title" ,
671+ @" $publicly_indexable" ,
672+ @" $content_schema" ,
673+ @" $quantity" ,
674+ @" $price" ,
675+ @" $currency" ,
676+ @" $sku" ,
677+ @" $product_name" ,
678+ @" $product_brand" ,
679+ @" $product_category" ,
680+ @" $product_variant" ,
681+ @" $condition" ,
682+ @" $rating_average" ,
683+ @" $rating_count" ,
684+ @" $rating_max" ,
685+ @" $address_street" ,
686+ @" $address_city" ,
687+ @" $address_region" ,
688+ @" $address_country" ,
689+ @" $address_postal_code" ,
690+ @" $latitude" ,
691+ @" $longitude" ,
692+ @" $image_captions" ,
693+ @" $custom_fields" ,
694+ ]];
695+
696+ // Add any extra fields to the content object.contentMetadata.customMetadata
697+
698+ for (NSString * key in dictionary.keyEnumerator ) {
699+ if (![fieldsAdded containsObject: key]) {
700+ object.contentMetadata .customMetadata [key] = dictionary[key];
701+ }
702+ }
703+
721704 return object;
722705}
723706
724707- (NSDictionary *_Nonnull) dictionary {
725708
726709 NSMutableDictionary *dictionary = [NSMutableDictionary dictionary ];
727710
711+ NSDictionary *contentDictionary = [self .contentMetadata dictionary ];
712+ if (contentDictionary.count ) [dictionary addEntriesFromDictionary: contentDictionary];
713+
728714 #define BNCFieldDefinesDictionaryFromSelf
729715 #include " BNCFieldDefines.h"
730716
@@ -741,9 +727,6 @@ - (NSDictionary*_Nonnull) dictionary {
741727
742728 #include " BNCFieldDefines.h"
743729
744- NSDictionary *contentDictionary = [self .contentMetadata dictionary ];
745- if (contentDictionary.count ) [dictionary addEntriesFromDictionary: contentDictionary];
746-
747730 return dictionary;
748731}
749732
0 commit comments