[SDK-363] Expose register device token#877
Conversation
- Add Iterable.registerDeviceToken(token) public API - Add IterableApi.registerDeviceToken bridge proxy - Add TurboModule spec entry in NativeRNIterableAPI.ts - Add iOS Swift/Obj-C++ glue with hex-to-Data conversion for APNS tokens - Add Android impl + old/new architecture stubs for FCM token pass-through - Update MockRNIterableAPI and unit tests - Add CHANGELOG entry under Unreleased
|
Qlty doesn't post analysis or coverage comments for contributors without a seat. An authorized user can grant @jferrao-itrbl a seat from this pull request's page in Qlty. |
joaodordio
left a comment
There was a problem hiding this comment.
Left some comments on the data(fromHex:) method that could cause regressions, but those are simple changes!
Suggestion:
private func data(fromHex hex: String) -> Data? {
guard !hex.isEmpty, hex.count.isMultiple(of: 2) else { return nil }
var data = Data(capacity: hex.count / 2)
var chars = hex.makeIterator()
while let high = chars.next(), let low = chars.next() {
guard let highValue = high.hexDigitValue, let lowValue = low.hexDigitValue else {
return nil
}
data.append(UInt8(highValue << 4 | lowValue))
}
return data
}Everything else looks good! Nice work!
|
|
||
| private let inboxSessionManager = InboxSessionManager() | ||
|
|
||
| private func data(fromHex hex: String) -> Data? { |
There was a problem hiding this comment.
data(fromHex:) returns a non-nil empty Data for empty input, so registerDeviceToken("") falls through and calls IterableAPI.register(token: Data()). That registers an empty APNS token with no error surfaced. Add an hex.isEmpty guard at the top of data(fromHex:) (or in registerDeviceToken before the call) and log the same ITBError so callers see something in their logs.
| @objc(registerDeviceToken:) | ||
| public func registerDeviceToken(token: String) { | ||
| ITBInfo() | ||
| guard let tokenData = data(fromHex: token) else { |
There was a problem hiding this comment.
if the token is empty, data(fromHex:) will not fail here because it returns an empty Data().
| var data = Data() | ||
| var chars = hex.makeIterator() | ||
| while let high = chars.next(), let low = chars.next() { | ||
| guard let highValue = high.hexDigitValue, let lowValue = low.hexDigitValue else { |
There was a problem hiding this comment.
NIT: Odd-length input gets silently truncated. The last hex char is consumed by high and the loop exits on low == nil, so we return a token shorter than the source with no error. APNS tokens are always even length, but customers paste tokens from unpredictable places and a malformed input should fail loudly. Reject inputs whose count isn't a multiple of 2 (return nil) so the existing ITBError branch fires.

🔹 JIRA Ticket(s) if any
✏️ Description
Expose
registerDeviceTokenin React Native bridge:Iterable.registerDeviceToken(token)public APIIterableApi.registerDeviceToken(token)NativeRNIterableAPI.tsMockRNIterableAPIand unit tests