-
Notifications
You must be signed in to change notification settings - Fork 43
[SDK-363] Expose register device token #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8cf83bb
b8cd996
df0ba48
2f690f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,3 +94,6 @@ docs/ | |
| # Local Netlify folder | ||
| .netlify | ||
| .metals/ | ||
|
|
||
| # Agents | ||
| .pi/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict/> | ||
| <dict> | ||
| <key>aps-environment</key> | ||
| <string>development</string> | ||
| </dict> | ||
| </plist> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,16 @@ import React | |
| IterableAPI.disableDeviceForCurrentUser() | ||
| } | ||
|
|
||
| @objc(registerDeviceToken:) | ||
| public func registerDeviceToken(token: String) { | ||
| ITBInfo() | ||
| guard let tokenData = data(fromHex: token) else { | ||
| ITBError("Could not convert token to Data: invalid hex string") | ||
| return | ||
| } | ||
| IterableAPI.register(token: tokenData) | ||
| } | ||
|
|
||
| @objc(getLastPushPayload:rejecter:) | ||
| public func getLastPushPayload(resolver: RCTPromiseResolveBlock, rejecter: RCTPromiseRejectBlock) | ||
| { | ||
|
|
@@ -599,6 +609,18 @@ import React | |
|
|
||
| private let inboxSessionManager = InboxSessionManager() | ||
|
|
||
| private func data(fromHex hex: String) -> Data? { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| return nil | ||
| } | ||
| data.append(UInt8(highValue << 4 | lowValue)) | ||
| } | ||
| return data | ||
| } | ||
|
|
||
| @objc func initialize( | ||
| withApiKey apiKey: String, | ||
| config configDict: NSDictionary, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the token is empty, data(fromHex:) will not fail here because it returns an empty Data().