Skip to content

Commit 243d2d9

Browse files
committed
Update tagging methods to pass string value to native bridge
1 parent c8be2f7 commit 243d2d9

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

ios/RCTOneSignal/RCTOneSignalEventEmitter.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,9 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
353353
}
354354

355355
RCT_EXPORT_METHOD(addTag:(NSString *)key value:(id)value) {
356-
if([value isKindOfClass:[NSNumber class]]) {
357-
//It is a number, convert to a string
358-
value = [value stringValue];
359-
}
360-
[OneSignal.User addTagWithKey:key value:value];
356+
[OneSignal.User addTagWithKey:key value:value];
361357
}
362358

363-
364359
RCT_EXPORT_METHOD(addTags:(NSDictionary *)tags) {
365360
[OneSignal.User addTags:tags];
366361
}

src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,20 @@ export namespace OneSignal {
430430
* Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing
431431
* messages. If the tag key already exists, it will be replaced with the value provided here.
432432
*/
433-
export function addTag(key: string, value: string | number | boolean) {
433+
export function addTag(key: string, value: string) {
434434
if (!isNativeModuleLoaded(RNOneSignal)) return;
435435

436-
if (!key || (!value && value !== '')) {
436+
if (!key || !value) {
437437
console.error('OneSignal: sendTag: must include a key and a value');
438438
return;
439439
}
440440

441-
RNOneSignal.addTag(key, value.toString());
441+
// forces values to be string types
442+
if (typeof value !== 'string') {
443+
value = String(value);
444+
}
445+
446+
RNOneSignal.addTag(key, value);
442447
}
443448

444449
/**
@@ -456,6 +461,14 @@ export namespace OneSignal {
456461
return;
457462
}
458463

464+
const convertedTags = tags as { [key: string]: any };
465+
Object.keys(tags).forEach(function (key) {
466+
// forces values to be string types
467+
if (typeof convertedTags[key] !== 'string') {
468+
convertedTags[key] = JSON.stringify(convertedTags[key]);
469+
}
470+
});
471+
459472
RNOneSignal.addTags(tags);
460473
}
461474

0 commit comments

Comments
 (0)