|
8 | 8 |
|
9 | 9 | #import <React/RCTLog.h> |
10 | 10 |
|
| 11 | +#import <Branch/BranchConstants.h> |
| 12 | + |
11 | 13 | #import "BranchUniversalObject+RNBranch.h" |
12 | 14 | #import "NSObject+RNBranch.h" |
13 | 15 | #import "RNBranchProperty.h" |
@@ -93,4 +95,67 @@ - (void)setExpirationDateWithString:(NSString *)expirationDate |
93 | 95 | self.expirationDate = [NSDate dateWithTimeIntervalSince1970:timegm(&expiration)]; |
94 | 96 | } |
95 | 97 |
|
| 98 | +#pragma mark - Code to support userCompletedAction:withState: |
| 99 | + |
| 100 | +/* |
| 101 | + * Until the native SDK supports this, the following is largely lifted from BUO.m. |
| 102 | + */ |
| 103 | + |
| 104 | +- (void)rnbranchUserCompletedAction:(NSString *)action withState:(NSDictionary *)state |
| 105 | +{ |
| 106 | + // Anticipate that the native SDK will support this. |
| 107 | + SEL sdkMethod = @selector(userCompletedAction:withState:); |
| 108 | + if ([self respondsToSelector:sdkMethod]) { |
| 109 | + [self performSelector:sdkMethod withObject:action withObject:state]; |
| 110 | + return; |
| 111 | + } |
| 112 | + |
| 113 | + NSMutableDictionary *actionPayload = [[NSMutableDictionary alloc] init]; |
| 114 | + NSDictionary *linkParams = [self getParamsForServerRequest]; |
| 115 | + if (self.canonicalIdentifier && linkParams) { |
| 116 | + actionPayload[BNCCanonicalIdList] = @[self.canonicalIdentifier]; |
| 117 | + actionPayload[self.canonicalIdentifier] = linkParams; |
| 118 | + |
| 119 | + // Add in custom params |
| 120 | + [actionPayload addEntriesFromDictionary:state]; |
| 121 | + |
| 122 | + [[Branch getInstance] userCompletedAction:action withState:actionPayload]; |
| 123 | + if (self.automaticallyListOnSpotlight && [action isEqualToString:BNCRegisterViewEvent]) |
| 124 | + [self listOnSpotlight]; |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +- (NSDictionary *)getParamsForServerRequest { |
| 129 | + NSMutableDictionary *temp = [[NSMutableDictionary alloc] init]; |
| 130 | + [self safeSetValue:self.canonicalIdentifier forKey:BRANCH_LINK_DATA_KEY_CANONICAL_IDENTIFIER onDict:temp]; |
| 131 | + [self safeSetValue:self.canonicalUrl forKey:BRANCH_LINK_DATA_KEY_CANONICAL_URL onDict:temp]; |
| 132 | + [self safeSetValue:self.title forKey:BRANCH_LINK_DATA_KEY_OG_TITLE onDict:temp]; |
| 133 | + [self safeSetValue:self.contentDescription forKey:BRANCH_LINK_DATA_KEY_OG_DESCRIPTION onDict:temp]; |
| 134 | + [self safeSetValue:self.imageUrl forKey:BRANCH_LINK_DATA_KEY_OG_IMAGE_URL onDict:temp]; |
| 135 | + if (self.contentIndexMode == ContentIndexModePrivate) { |
| 136 | + [self safeSetValue:@(0) forKey:BRANCH_LINK_DATA_KEY_PUBLICLY_INDEXABLE onDict:temp]; |
| 137 | + } |
| 138 | + else { |
| 139 | + [self safeSetValue:@(1) forKey:BRANCH_LINK_DATA_KEY_PUBLICLY_INDEXABLE onDict:temp]; |
| 140 | + } |
| 141 | + [self safeSetValue:self.keywords forKey:BRANCH_LINK_DATA_KEY_KEYWORDS onDict:temp]; |
| 142 | + [self safeSetValue:@(1000 * [self.expirationDate timeIntervalSince1970]) forKey:BRANCH_LINK_DATA_KEY_CONTENT_EXPIRATION_DATE onDict:temp]; |
| 143 | + [self safeSetValue:self.type forKey:BRANCH_LINK_DATA_KEY_CONTENT_TYPE onDict:temp]; |
| 144 | + [self safeSetValue:self.currency forKey:BNCPurchaseCurrency onDict:temp]; |
| 145 | + if (self.price) { |
| 146 | + // have to add if statement because safeSetValue only accepts objects so even if self.price is not set |
| 147 | + // a valid NSNumber object will be created and the request will have amount:0 in all cases. |
| 148 | + [self safeSetValue:[NSNumber numberWithFloat:self.price] forKey:BNCPurchaseAmount onDict:temp]; |
| 149 | + } |
| 150 | + |
| 151 | + [temp addEntriesFromDictionary:[self.metadata copy]]; |
| 152 | + return [temp copy]; |
| 153 | +} |
| 154 | + |
| 155 | +- (void)safeSetValue:(NSObject *)value forKey:(NSString *)key onDict:(NSMutableDictionary *)dict { |
| 156 | + if (value) { |
| 157 | + dict[key] = value; |
| 158 | + } |
| 159 | +} |
| 160 | + |
96 | 161 | @end |
0 commit comments