Reputation: 133
my app is working fine in ios 6.. it uploading and downloading the data from amazon web server s3..but when i upgrade my ios 6 to ios 7...i got alert message " cannot connect to server" this error in log window
"Exception = AmazonServiceException { RequestId:5DC8AEF01DD9FB91, ErrorCode:AccessDenied, Message:AWS authentication requires a valid Date or x-amz-date header} ".
to solve this problem i upgrade my aws ios sdk 1.0.0 to aws ios sdk 1.6.1.and try to run my app it freezes for 10-12 second then app running.
so please can anyone tell me the solution how i remove " x-amz-date header" problem in aws ios sdk 1.0.0 and its alternate freeze problem in aws ios sdk 1.6.1..
Upvotes: 7
Views: 2508
Reputation: 1818
I was had the same problem and after updating to version 1.6 of AWS SDK the problem has gone.
Upvotes: 0
Reputation: 133
Finally I Got the Solution and This works for me,i used awsios sdk 1.3.1 instead of awsios sdk 1.6.1. and make some changes in S3Request.m in the method
-(AmazonURLRequest *)configureURLRequest{
....
....
NSString *checkFormat =[self.date stringWithRFC822Format];
if(![checkFormat hasSuffix:@":00"])
checkFormat = [NSString stringWithFormat:@"%@+00:00",checkFormat];
[self.urlRequest setValue:checkFormat forHTTPHeaderField:kHttpHdrDate];
...
...
}
Upvotes: 0
Reputation: 3759
In AmazonSDKUtil.m
, we have the following methods:
+(NSDate *)convertStringToDate:(NSString *)string usingFormat:(NSString *)dateFormat
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:dateFormat];
[dateFormatter setLocale:[AmazonSDKUtil timestampLocale]];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSDate *parsed = [dateFormatter dateFromString:string];
NSDate *localDate = [parsed dateByAddingTimeInterval:_clockskew];
[dateFormatter release];
return localDate;
}
+(NSString *)convertDateToString:(NSDate *)date usingFormat:(NSString *)dateFormat
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[dateFormatter setDateFormat:dateFormat];
[dateFormatter setLocale:[AmazonSDKUtil timestampLocale]];
NSDate *realDate = [date dateByAddingTimeInterval:-1*_clockskew];
NSString *formatted = [dateFormatter stringFromDate:realDate];
[dateFormatter release];
return formatted;
}
In older versions of the SDK, the locale and timezone weren't properly set to en_US
and GMT
. This may cause issues depending on your device locale and timezone settings. The latest version of the SDK fixes the issue. If, for some reason, you cannot update the SDK, you can modify AmazonSDKUtil.m
and explicitly set locale and timezone values.
EDIT:
If you run the following code snippet on iOS 6 and iOS 7, you can see how locale setting affects date format.
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"PDT"];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
NSString *dateWithoutTimezoneAndLocale = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"Date 1: %@", dateWithoutTimezoneAndLocale);
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString *dateWithTimezoneAndLocale = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"Date 2: %@", dateWithTimezoneAndLocale);
On iOS 6
Date 1: Wed, 25 Sep 2013 16:25:29 PDT
Date 2: Wed, 25 Sep 2013 23:25:29 GMT
On iOS 7
Date 1: Wed, 25 Sep 2013 16:24:11 GMT-7
Date 2: Wed, 25 Sep 2013 23:24:11 GMT
As you stated before, the behavior of NSDateFormatter
changed in iOS 7; however, the root cause of this issue is that you are not explicitly setting the locale to en_US
. When the locale is set to something other than en_US
, it may cause an issue. This is why we explicitly set the locale in the latest version of our SDK so that it runs on devices with any locale settings.
Hope this makes sense,
Upvotes: 3
Reputation: 460
I have submitted a bug report to Apple (to find out if this a bug or not).
In the meantime I created an awful hack that solves the issue in S3Request.m in the method configureURLRequest:
NSString *checkFormat =[self.date requestFormat];
if(![checkFormat hasSuffix:@":00"])
checkFormat = [NSString stringWithFormat:@"%@:00",checkFormat];
[self.urlRequest setValue:checkFormat forHTTPHeaderField:kHttpHdrDate];
This may not be the same in your version of the AWS SDK.
I would not use this fix in the long term - I will post any response from the Apple bug report team here once they come back with a recommended solution
I also posted a question here: https://forums.aws.amazon.com/thread.jspa?threadID=135829#
EDIT: in the latest version of the toolkit the hack is:
NSString *checkFormat =[self.date stringWithRFC822Format];
if(![checkFormat hasSuffix:@":00"])
checkFormat = [NSString stringWithFormat:@"%@:00",checkFormat];
[self.urlRequest setValue:checkFormat forHTTPHeaderField:kHttpHdrDate];
Upvotes: 0