Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit 4c3f375

Browse files
authored
invoke failure handler on invalid cases, don't enforce token size (#21)
* invoke failure handler in regsterToken when provided PushServicePlatform is invalid * don't enforce token to be 32 bytes
1 parent 4f6fcdd commit 4c3f375

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010
- nothing yet
1111

1212
#### Changed
13-
- nothing yet
13+
- `registerToken` no longer checks the token to be 32 bytes/64 hex chars
1414

1515
#### Fixed
16-
- nothing yet
16+
- `registerToken` now calls the failure handler if an invalid `PushServicePlatform` is passed in
1717

1818

1919
## [2.1.0](https://github.com/Iterable/iterable-ios-sdk/releases/tag/2.1.0)

Iterable-iOS-SDK/IterableAPI.m

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -312,38 +312,37 @@ - (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePla
312312
{
313313
NSString *hexToken = [token hexadecimalString];
314314

315-
if ([hexToken length] != 64) {
316-
LogError(@"registerToken: invalid token");
317-
} else {
318-
UIDevice *device = [UIDevice currentDevice];
319-
NSString *psp = [IterableAPI pushServicePlatformToString:pushServicePlatform];
320-
321-
if (!psp) {
322-
LogError(@"registerToken: invalid pushServicePlatform");
323-
return;
315+
UIDevice *device = [UIDevice currentDevice];
316+
NSString *psp = [IterableAPI pushServicePlatformToString:pushServicePlatform];
317+
318+
if (!psp) {
319+
LogError(@"registerToken: invalid pushServicePlatform");
320+
if (onFailure) {
321+
onFailure(@"Not registering device token - the specified PushServicePlatform is invalid", [[NSData alloc] init]);
324322
}
325-
326-
NSDictionary *args = @{
327-
@"email": self.email,
328-
@"device": @{
329-
@"token": hexToken,
330-
@"platform": psp,
331-
@"applicationName": appName,
332-
@"dataFields": @{
333-
@"name": [device name],
334-
@"localizedModel": [device localizedModel],
335-
@"userInterfaceIdiom": [IterableAPI userInterfaceIdiomEnumToString:[device userInterfaceIdiom]],
336-
@"identifierForVendor": [[device identifierForVendor] UUIDString],
337-
@"systemName": [device systemName],
338-
@"systemVersion": [device systemVersion],
339-
@"model": [device model]
340-
}
341-
}
342-
};
343-
LogDebug(@"sending registerToken request with args %@", args);
344-
NSURLRequest *request = [self createRequestForAction:@"users/registerDeviceToken" withArgs:args];
345-
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];
323+
return;
346324
}
325+
326+
NSDictionary *args = @{
327+
@"email": self.email,
328+
@"device": @{
329+
@"token": hexToken,
330+
@"platform": psp,
331+
@"applicationName": appName,
332+
@"dataFields": @{
333+
@"name": [device name],
334+
@"localizedModel": [device localizedModel],
335+
@"userInterfaceIdiom": [IterableAPI userInterfaceIdiomEnumToString:[device userInterfaceIdiom]],
336+
@"identifierForVendor": [[device identifierForVendor] UUIDString],
337+
@"systemName": [device systemName],
338+
@"systemVersion": [device systemVersion],
339+
@"model": [device model]
340+
}
341+
}
342+
};
343+
LogDebug(@"sending registerToken request with args %@", args);
344+
NSURLRequest *request = [self createRequestForAction:@"users/registerDeviceToken" withArgs:args];
345+
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];
347346
}
348347

349348
// documented in IterableAPI.h
@@ -473,6 +472,7 @@ - (void)trackPurchase:(NSNumber *)total items:(NSArray<CommerceItem> *)items dat
473472
};
474473
}
475474
NSURLRequest *request = [self createRequestForAction:@"commerce/trackPurchase" withArgs:args];
476-
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];}
475+
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];
476+
}
477477

478478
@end

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $ pod install
5353

5454
Congratulations! You have now imported the Iterable SDK into your project!
5555

56-
> If your project is built with `Swift`, you will need a `bridging header`. See [here](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) for more information on how to create one.
56+
> &#x2139; If your project is built with `Swift`, you will need a `bridging header`. See [here](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) for more information on how to create one.
5757
5858
# Using the SDK
5959

@@ -72,6 +72,11 @@ Congratulations! You have now imported the Iterable SDK into your project!
7272
3. **Send the token to Iterable**
7373
Use the SDK's `- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform` to send the token to Iterable
7474
***Device tokens can change, so your app needs to reregister every time it is launched and pass the received token back to your server***. Don't cache your token on the device; send it every time you receive one.
75+
This is the practice recommended by Apple; see the documentation [here](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW25). Specifically,
76+
77+
> &#x26A0; Device tokens can change, so your app needs to reregister every time it is launched and pass the received token back to your server. If you fail to update the device token, remote notifications might not make their way to the user’s device. Device tokens always change when the user restores backup data to a new device or computer or reinstalls the operating system. When migrating data to a new device or computer, the user must launch your app once before remote notifications can be delivered to that device.
78+
79+
> &#x26A0; Never cache a device token; always get the token from the system whenever you need it. If your app previously registered for remote notifications, calling the registerForRemoteNotifications method again does not incur any additional overhead, and iOS returns the existing device token to your app delegate immediately. In addition, iOS calls your delegate method any time the device token changes, not just in response to your app registering or re-registering.
7580
7681
#### Putting it all together:
7782

0 commit comments

Comments
 (0)