// // BranchUniversalObject+RNBranch.m // RNBranch // // Created by Jimmy Dee on 1/26/17. // Copyright © 2017 Branch Metrics. All rights reserved. // #import #import "BranchUniversalObject+RNBranch.h" #import "NSObject+RNBranch.h" #import "RNBranchProperty.h" @implementation BranchUniversalObject(RNBranch) + (NSDictionary *)supportedProperties { static NSDictionary *_universalObjectProperties; static dispatch_once_t once = 0; dispatch_once(&once, ^{ _universalObjectProperties = @{ @"automaticallyListOnSpotlight": [RNBranchProperty propertyWithSetterSelector:@selector(setAutomaticallyListOnSpotlightWithNumber:) type:NSNumber.class], @"canonicalUrl": [RNBranchProperty propertyWithSetterSelector:@selector(setCanonicalUrl:) type:NSString.class], @"contentDescription": [RNBranchProperty propertyWithSetterSelector:@selector(setContentDescription:) type:NSString.class], @"contentImageUrl": [RNBranchProperty propertyWithSetterSelector:@selector(setImageUrl:) type:NSString.class], @"contentIndexingMode": [RNBranchProperty propertyWithSetterSelector:@selector(setContentIndexingMode:) type:NSString.class], @"currency": [RNBranchProperty propertyWithSetterSelector:@selector(setCurrency:) type:NSString.class], @"expirationDate": [RNBranchProperty propertyWithSetterSelector:@selector(setExpirationDateWithString:) type:NSString.class], @"keywords": [RNBranchProperty propertyWithSetterSelector:@selector(setKeywords:) type:NSArray.class], @"metadata": [RNBranchProperty propertyWithSetterSelector:@selector(setMetadata:) type:NSDictionary.class], @"price": [RNBranchProperty propertyWithSetterSelector:@selector(setPriceWithNumber:) type:NSNumber.class], @"title": [RNBranchProperty propertyWithSetterSelector:@selector(setTitle:) type:NSString.class], @"type": [RNBranchProperty propertyWithSetterSelector:@selector(setType:) type:NSString.class] }; }); return _universalObjectProperties; } - (instancetype)initWithMap:(NSDictionary *)map { NSString *canonicalIdentifier = map[@"canonicalIdentifier"]; NSMutableDictionary *mutableMap = map.mutableCopy; [mutableMap removeObjectForKey:@"canonicalIdentifier"]; self = [self initWithCanonicalIdentifier:canonicalIdentifier]; if (self) { [self setSupportedPropertiesWithMap:mutableMap]; } return self; } - (void)setContentIndexingMode:(NSString *)contentIndexingMode { if ([contentIndexingMode isEqualToString:@"private"]) { self.contentIndexMode = ContentIndexModePrivate; } else if ([contentIndexingMode isEqualToString:@"public"]) { self.contentIndexMode = ContentIndexModePublic; } else { RCTLogWarn(@"Invalid value \"%@\" for \"contentIndexingMode\". Supported values are \"public\" and \"private\".", contentIndexingMode); } } - (void)setPriceWithNumber:(NSNumber *)price { self.price = price.floatValue; } - (void)setAutomaticallyListOnSpotlightWithNumber:(NSNumber *)flag { self.automaticallyListOnSpotlight = flag.boolValue; } - (void)setExpirationDateWithString:(NSString *)expirationDate { struct tm expiration; if (!strptime(expirationDate.UTF8String, "%Y-%m-%dT%H:%M:%S", &expiration)) { RCTLogWarn(@"Invalid expiration date format. Valid format is YYYY-mm-ddTHH:MM:SS, e.g. 2017-02-01T00:00:00. All times UTC."); return; } self.expirationDate = [NSDate dateWithTimeIntervalSince1970:timegm(&expiration)]; } @end