Skip to content

Commit d5b4209

Browse files
committed
checking for failure block before calling it in sendTags
1 parent e24076e commit d5b4209

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,26 +1263,32 @@ + (void)sendTags:(NSDictionary*)keyValuePair onSuccess:(OSResultSuccessBlock)suc
12631263

12641264
// return if the user has not granted privacy permissions
12651265
if ([self shouldLogMissingPrivacyConsentErrorWithMethodName:@"sendTags:onSuccess:onFailure:"]) {
1266-
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"}];
1267-
failureBlock(error);
1266+
if (failureBlock) {
1267+
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"}];
1268+
failureBlock(error);
1269+
}
12681270
return;
12691271
}
12701272

12711273

12721274
if (![NSJSONSerialization isValidJSONObject:keyValuePair]) {
12731275
NSString *errorMessage = [NSString stringWithFormat:@"sendTags JSON Invalid: The following key/value pairs you attempted to send as tags are not valid JSON: %@", keyValuePair];
12741276
onesignal_Log(ONE_S_LL_WARN, errorMessage);
1275-
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : errorMessage}];
1276-
failureBlock(error);
1277+
if (failureBlock) {
1278+
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : errorMessage}];
1279+
failureBlock(error);
1280+
}
12771281
return;
12781282
}
12791283

12801284
for (NSString *key in [keyValuePair allKeys]) {
12811285
if ([keyValuePair[key] isKindOfClass:[NSDictionary class]]) {
12821286
NSString *errorMessage = @"sendTags Tags JSON must not contain nested objects";
12831287
onesignal_Log(ONE_S_LL_WARN, errorMessage);
1284-
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : errorMessage}];
1285-
failureBlock(error);
1288+
if (failureBlock) {
1289+
NSError *error = [NSError errorWithDomain:@"com.onesignal.tags" code:0 userInfo:@{@"error" : errorMessage}];
1290+
failureBlock(error);
1291+
}
12861292
return;
12871293
}
12881294
}

0 commit comments

Comments
 (0)