AWS Mobile Blog

Clock Skew Fix

by Singh, Pardeep | on | Permalink | Comments |  Share

Version 2 of the AWS Mobile SDK

  • This article and sample apply to Version 1 of the AWS Mobile SDK. If you are building new apps, we recommend you use Version 2. For details, please visit the AWS Mobile SDK page.
  • This content is being maintained for historical reference.

Clock Skew Adjustment

Previously, we showed you to handle device clock skew when communicating with AWS services using the Mobile SDKs (Android and iOS). We have added a new feature that automatically adjusts the device clock skew for you.

For Android, you don’t have to worry about whether it’s a synchronous or asynchronous call. Our code automatically adjusts the device clock skew, and resigns and retries the request for you. For iOS, synchronous calls are automatically adjusted and retried too. But, for iOS asynchronous calls, the behavior is different because we do not retry. That is something that client code must handle. When the device time is off, we catch the exception, and adjust the device clock skew. All the subsequent requests won’t have the clock skew issue, but you would still need to retry the current request. We provide an additional flag that will help you determine if the exception was the clock skew exception and device clock skew has been fixed. This additional flag is a field of NSDictionary *userInfo, which is a property of both NSError and NSException. You must use the delegate methods to handle the device clock skew issue. Here is a snippet of how you would implement these delegate methods:

There are two approaches to retry when the request fails. If you’re using [AmazonErrorHandler shouldNotThrowExceptions] in your code then you would implement the following delegate method:

-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)theError
{
    BOOL isClockSkewError = [[theError userInfo] valueForKey:@"AWSClockSkewError"];
    if(isClockSkewError) {
        // update the request
        // resend the request
    }
}

The default behavior of the AWS SDK for iOS is to throw an exception, but if you’re using [AmazonErrorHandler shouldThrowExceptions] in your code, then you would implement the following delegate method:

-(void)request:(AmazonServiceRequest *)request didFailWithServiceException:(AmazonServiceException *)theException
{
    BOOL isClockSkewError = [[theException userInfo] valueForKey:@"AWSClockSkewError"];
    if(isClockSkewError) {
        // update the request
        // resend the request
    }
}