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

Commit c34f551

Browse files
davidtruongdontgitit
authored andcommitted
Code cleanup and added in documentation (#25)
* Code cleanup and added in documentation * Code review fixes, changed call signatures for disablePush * changes and fixes * use NSNull instead of nil, and check that email and hexToken exist * only check email if needed
1 parent 6848239 commit c34f551

File tree

4 files changed

+144
-27
lines changed

4 files changed

+144
-27
lines changed

Artifacts/include/Iterable-iOS-SDK/IterableAPI.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
5151
*/
5252
@property(nonatomic, readonly, copy) NSString *email;
5353

54+
/**
55+
The hex representation of this device token
56+
*/
57+
@property(nonatomic, readonly, copy) NSString *hexToken;
5458

5559
/////////////////////////////////
5660
/// @name Creating an IterableAPI
@@ -152,6 +156,51 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
152156
*/
153157
- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
154158

159+
/////////////////////////////
160+
/// @name Disabling a device
161+
/////////////////////////////
162+
163+
/*!
164+
@method
165+
166+
@abstract Disable this device's token in Iterable, for the current user
167+
*/
168+
- (void)disableDeviceForCurrentUser;
169+
170+
/*!
171+
@method
172+
173+
@abstract Disable this device's token in Iterable, for all users with this device
174+
*/
175+
- (void)disableDeviceForAllUsers;
176+
177+
/*!
178+
@method
179+
180+
@abstract Disable this device's token in Iterable, for the current user, with custom completion blocks
181+
182+
@param onSuccess OnSuccessHandler to invoke if disabling the token is successful
183+
@param onFailure OnFailureHandler to invoke if disabling the token fails
184+
185+
@see OnSuccessHandler
186+
@see OnFailureHandler
187+
*/
188+
- (void)disableDeviceForCurrentUserWithOnSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
189+
190+
/*!
191+
@method
192+
193+
@abstract Disable this device's token in Iterable, for all users with this device, with custom completion blocks
194+
195+
@param onSuccess OnSuccessHandler to invoke if disabling the token is successful
196+
@param onFailure OnFailureHandler to invoke if disabling the token fails
197+
198+
@see OnSuccessHandler
199+
@see OnFailureHandler
200+
*/
201+
- (void)disableDeviceForAllUsersWithOnSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
202+
203+
155204
/////////////////////////
156205
/// @name Tracking events
157206
/////////////////////////

Artifacts/libIterable-iOS-SDK.a

38.3 KB
Binary file not shown.

Iterable-iOS-SDK/IterableAPI.h

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
5151
*/
5252
@property(nonatomic, readonly, copy) NSString *email;
5353

54+
/**
55+
The hex representation of this device token
56+
*/
57+
@property(nonatomic, readonly, copy) NSString *hexToken;
5458

5559
/////////////////////////////////
5660
/// @name Creating an IterableAPI
@@ -153,10 +157,48 @@ typedef NS_ENUM(NSInteger, PushServicePlatform) {
153157
- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
154158

155159
/////////////////////////////
156-
/// @name Disabling a token
160+
/// @name Disabling a device
157161
/////////////////////////////
158162

159-
- (void)disableToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform;
163+
/*!
164+
@method
165+
166+
@abstract Disable this device's token in Iterable, for the current user
167+
*/
168+
- (void)disableDeviceForCurrentUser;
169+
170+
/*!
171+
@method
172+
173+
@abstract Disable this device's token in Iterable, for all users with this device
174+
*/
175+
- (void)disableDeviceForAllUsers;
176+
177+
/*!
178+
@method
179+
180+
@abstract Disable this device's token in Iterable, for the current user, with custom completion blocks
181+
182+
@param onSuccess OnSuccessHandler to invoke if disabling the token is successful
183+
@param onFailure OnFailureHandler to invoke if disabling the token fails
184+
185+
@see OnSuccessHandler
186+
@see OnFailureHandler
187+
*/
188+
- (void)disableDeviceForCurrentUserWithOnSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
189+
190+
/*!
191+
@method
192+
193+
@abstract Disable this device's token in Iterable, for all users with this device, with custom completion blocks
194+
195+
@param onSuccess OnSuccessHandler to invoke if disabling the token is successful
196+
@param onFailure OnFailureHandler to invoke if disabling the token fails
197+
198+
@see OnSuccessHandler
199+
@see OnFailureHandler
200+
*/
201+
- (void)disableDeviceForAllUsersWithOnSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure;
160202

161203

162204
/////////////////////////

Iterable-iOS-SDK/IterableAPI.m

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ - (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePla
311311
- (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure
312312
{
313313
NSString *hexToken = [token hexadecimalString];
314+
_hexToken = hexToken;
314315

315316
UIDevice *device = [UIDevice currentDevice];
316317
NSString *psp = [IterableAPI pushServicePlatformToString:pushServicePlatform];
@@ -344,33 +345,58 @@ - (void)registerToken:(NSData *)token appName:(NSString *)appName pushServicePla
344345
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];
345346
}
346347

347-
- (void)disableToken:(NSData *)token appName:(NSString *)appName pushServicePlatform:(PushServicePlatform)pushServicePlatform {
348-
NSString *hexToken = [token hexadecimalString];
349-
350-
if ([hexToken length] != 64) {
351-
NSLog(@"registerToken: invalid token");
352-
} else {
353-
NSString *psp = [IterableAPI pushServicePlatformToString:pushServicePlatform];
354-
355-
if (!psp) {
356-
LogError(@"disableToken: invalid pushServicePlatform");
357-
return;
348+
/*!
349+
@method
350+
351+
@abstract Disable this device's token in Iterable with custom completion blocks. `allUsers` indicates whether to disable for all users with this token, or only current user
352+
353+
@param onSuccess OnSuccessHandler to invoke if disabling the token is successful
354+
@param onFailure OnFailureHandler to invoke if disabling the token fails
355+
356+
@see OnSuccessHandler
357+
@see OnFailureHandler
358+
*/
359+
- (void)disableDevice:(BOOL)allUsers onSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure
360+
{
361+
if (!self.hexToken || (!allUsers && !self.email)) {
362+
LogWarning(@"disableDevice: email or token not yet registered");
363+
if (onFailure) {
364+
onFailure(@"Not disabling device - you must call registerToken first, and sharedInstance must have an email", [[NSData alloc] init]);
358365
}
359-
360-
NSDictionary *args = @{
361-
@"email": self.email,
362-
@"token": hexToken
363-
};
364-
LogDebug(@"sending disableToken request with args %@", args);
365-
NSURLRequest *request = [self createRequestForAction:@"users/disableDevice" withArgs:args];
366-
[self sendRequest:request onSuccess:^(NSDictionary *data)
367-
{
368-
LogDebug(@"disable succeeded to send, got data: %@", data);
369-
} onFailure:^(NSString *reason, NSData *data)
370-
{
371-
LogDebug(@"disable failed to send: %@. Got data %@", reason, data);
372-
}];
366+
return;
373367
}
368+
NSDictionary *args = @{
369+
@"email": allUsers ? [NSNull null]: self.email,
370+
@"token": self.hexToken
371+
};
372+
373+
LogDebug(@"sending disableToken request with args %@", args);
374+
NSURLRequest *request = [self createRequestForAction:@"users/disableDevice" withArgs:args];
375+
[self sendRequest:request onSuccess:onSuccess onFailure:onFailure];
376+
}
377+
378+
// documented in IterableAPI.h
379+
- (void)disableDeviceForCurrentUser
380+
{
381+
return [self disableDeviceForCurrentUserWithOnSuccess:[IterableAPI defaultOnSuccess:@"disableDevice"] onFailure:[IterableAPI defaultOnFailure:@"disableDevice"]];
382+
}
383+
384+
// documented in IterableAPI.h
385+
- (void)disableDeviceForAllUsers
386+
{
387+
return [self disableDeviceForAllUsersWithOnSuccess:[IterableAPI defaultOnSuccess:@"disableDevice"] onFailure:[IterableAPI defaultOnFailure:@"disableDevice"]];
388+
}
389+
390+
// documented in IterableAPI.h
391+
- (void)disableDeviceForCurrentUserWithOnSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure
392+
{
393+
return [self disableDevice:FALSE onSuccess:onSuccess onFailure:onFailure];
394+
}
395+
396+
// documented in IterableAPI.h
397+
- (void)disableDeviceForAllUsersWithOnSuccess:(OnSuccessHandler)onSuccess onFailure:(OnFailureHandler)onFailure
398+
{
399+
return [self disableDevice:TRUE onSuccess:onSuccess onFailure:onFailure];
374400
}
375401

376402
// documented in IterableAPI.h

0 commit comments

Comments
 (0)