Skip to content

Commit b72b3f2

Browse files
committed
Calling the failure block of send tags for bad input
Previously we would log a warning and return on bad input for the sendTags method. Now we will also call the failure block with an error object with information on what went wrong. This fixes #951
1 parent a8a4113 commit b72b3f2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,17 +1248,27 @@ + (void)sendTags:(NSDictionary*)keyValuePair {
12481248
+ (void)sendTags:(NSDictionary*)keyValuePair onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
12491249

12501250
// return if the user has not granted privacy permissions
1251-
if ([self shouldLogMissingPrivacyConsentErrorWithMethodName:@"sendTags:onSuccess:onFailure:"])
1251+
if ([self shouldLogMissingPrivacyConsentErrorWithMethodName:@"sendTags:onSuccess:onFailure:"]) {
1252+
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : @"Your application has called sendTags:onSuccess:onFailure: before the user granted privacy permission. Please call `consentGranted(bool)` in order to provide user privacy consent"}];
1253+
failureBlock(error);
12521254
return;
1255+
}
1256+
12531257

12541258
if (![NSJSONSerialization isValidJSONObject:keyValuePair]) {
1255-
onesignal_Log(ONE_S_LL_WARN, [NSString stringWithFormat:@"sendTags JSON Invalid: The following key/value pairs you attempted to send as tags are not valid JSON: %@", keyValuePair]);
1259+
NSString *errorMessage = [NSString stringWithFormat:@"sendTags JSON Invalid: The following key/value pairs you attempted to send as tags are not valid JSON: %@", keyValuePair];
1260+
onesignal_Log(ONE_S_LL_WARN, errorMessage);
1261+
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : errorMessage}];
1262+
failureBlock(error);
12561263
return;
12571264
}
12581265

12591266
for (NSString *key in [keyValuePair allKeys]) {
12601267
if ([keyValuePair[key] isKindOfClass:[NSDictionary class]]) {
1261-
onesignal_Log(ONE_S_LL_WARN, @"sendTags Tags JSON must not contain nested objects");
1268+
NSString *errorMessage = @"sendTags Tags JSON must not contain nested objects";
1269+
onesignal_Log(ONE_S_LL_WARN, errorMessage);
1270+
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : errorMessage}];
1271+
failureBlock(error);
12621272
return;
12631273
}
12641274
}

0 commit comments

Comments
 (0)