@@ -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