Accessing localized error message from ASIHTTPrequest calls - localization

I'm using the ASIHTTPRequest to perform some HTTP calls. In a certain case when the network isn't available, I display a dialog with the error from the NSError object returned. My problem occurs when I change my language settings (to Spanish). The localizedDescription always returns in English:
NSLog(#"userInfo: %#", [error userInfo]);
NSLog(#"localizedDescription: %#", [error localizedDescription]);
prints:
2012-04-05 22:02:05.519 MyApp[18644:207] userInfo: {
NSLocalizedDescription = "A connection failure occurred";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=61 \"The operation couldn\U2019t be completed. Conexi\U00f3n rechazada\" UserInfo=0x594f880 {}";
}
2012-04-05 22:02:05.519 MyApp[18644:207] localizedDescription: A connection failure occurred
localizedDescription is still in English, but inside [error userInfo], in the NSUnderlyingError, there is a Spanish translation available, but I don't know how to access it via the NSError object returned.
A similar question was previous asked, but the answer is not satisfactory and not scalable for all possible error messages.

Related

issue while Logging-In using Parse

I have made an app is which user can sign-in and sign-up using Parse.
But I am unable to to sign-in.
I copied the login-code from Parse
The code is:
- (IBAction)didTapLogin:(id)sender
{
[PFUser logInWithUsernameInBackground:#"Rahul#gmail.com" password:#"mypass"
block:^(PFUser *user, NSError *error) {
if (user) {
NSLog(#"SUCCESS");
} else {
NSLog(#"%#",error);
}
}];
}
I have set Up the Keys already in App-Delegate.m
I am getting following Error:
[Error]: invalid login parameters (Code: 101, Version: 1.7.2)
Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x7feefa437070 {code=101, temporary=0, error=invalid login parameters, originalError=Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn’t be completed. (NSURLErrorDomain error -1011.)"}
What's the issue in code.As I have done nothing with it.

Amazon s3 Image Upload (cognito id null)

Image is not uploading in a amazon s3 . I was using the old library all the upload was working fine but for ios 8 i use new sdk and create new conginito id
now i am facing errors. any help will be appreciated
My code is
AWSS3TransferManagerUploadRequest *request = [[AWSS3TransferManagerUploadRequest alloc] init];
request.bucket = #"my bucket name";
request.key = #"my cognitio id";
request.body =[NSURL fileURLWithPath:path];
request.contentType = #"image/png";
[[transferManager upload:request] continueWithExecutor:[BFExecutor mainThreadExecutor]
withBlock:^id(BFTask *task) {
NSLog(#"ckmdkcd dvdsv");
if (task.error) {
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
case AWSS3TransferManagerErrorPaused:
break;
default:
NSLog(#"Error: %#", task.error);
break;
}
} else {
// Unknown error.
NSLog(#"Error: %#", task.error);
}
}
if (task.result) {
AWSS3TransferManagerUploadOutput *uploadOutput = task.result;
// The file uploaded successfully.
NSLog(#"result = %#",task.result);
}
return nil;
}];
I got the following response
AWSiOSSDKv2 [Error] AWSIdentityProvider.m line:185 | __51-[AWSAbstractCognitoIdentityProvider getIdentityId]_block_invoke169 | GetId failed. Error is [Error Domain=NSURLErrorDomain Code=-1003 "The operation couldn’t be completed. (NSURLErrorDomain error -1003.)" UserInfo=0x7f9b987aabf0 {NSErrorFailingURLStringKey=https://cognito-identity.(null).amazonaws.com/, NSErrorFailingURLKey=https://cognito-identity.(null).amazonaws.com/, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSUnderlyingError=0x7f9b9a839480 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1003.)"}]
2015-04-14 08:13:16.326 newtest[6611:172200] AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:534 | __40-[AWSCognitoCredentialsProvider refresh]_block_invoke350 | Unable to refresh. Error is [Error Domain=NSURLErrorDomain Code=-1003 "The operation couldn’t be completed. (NSURLErrorDomain error -1003.)" UserInfo=0x7f9b987aabf0 {NSErrorFailingURLStringKey=https://cognito-identity.(null).amazonaws.com/, NSErrorFailingURLKey=https://cognito-identity.(null).amazonaws.com/, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSUnderlyingError=0x7f9b9a839480 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1003.)"}]
2015-04-14 08:13:16.328 newtest[6611:172071] ckmdkcd dvdsv
2015-04-14 08:13:16.328 newtest[6611:172071] Error: Error Domain=NSURLErrorDomain Code=-1003 "The operation couldn’t be completed. (NSURLErrorDomain error -1003.)" UserInfo=0x7f9b987aabf0 {NSErrorFailingURLStringKey=https://cognito-identity.(null).amazonaws.com/, NSErrorFailingURLKey=https://cognito-identity.(null).amazonaws.com/, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSUnderlyingError=0x7f9b9a839480 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1003.)"}
I am also setting cognitio id in app delegate.
Based on the fact that you seeing https://cognito-identity.(null).amazonaws.com/ in the error, it would lead me to believe you are not correctly setting the region when creating the AWSCognitoCredentialsProvider. Please double check that you are not setting this to AWSRegionUnknown.
Update 2015-04-17: Here is the list of Region constants. You should set this to the region where your identity pool exists. Currently Amazon Cognito is only available in AWSRegionUSEast1 or AWSRegionEUWest1.
Note, the region of your identity pool has nothing to do the region of other AWS services you may use in your application. You can use an identity pool in AWSRegionUSEast1 to access resources in AWSRegionSAEast1, for instance.

NSURL Error code extraction

I try to do my NSURL error-handling and have a little problem.
When i'm getting an error i want to handle it different for different error-codes.
In my case i want to check if the error that i'm getting is the one with errorcode 1005.
This is what I get when I print as follows:
NSLog(#"%#",error);
Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x1700ff000 {NSErrorFailingURLStringKey=MyURL, NSErrorFailingURLKey=MyURL, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSURLSessionDownloadTaskResumeData=<CFData 0x17025a580 [0x1936b2c80]>{length = 3640, capacity = 4096, bytes = 0x3c3f786d6c2076657273696f6e3d2231 ... 2f706c6973743e0a}, NSUnderlyingError=0x17025cf80 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}
and this is what I want to extract from it:
-1005
I already searched for it and found a solution which doesn't work. (I get EXC_BAD_ACCESS)
NSLog(#"%#", [error code]);
Afterwards I want to compare it similar to:
if(error.code == -1005){
//handle error
}
You can't use:
NSLog(#"%#", [error code]);
Because code is NSInteger. Use:
NSLog(#"%d", [error code]);
Refer: NSError Class Reference for more details

userInfo Keys used in Core Data Validation Errors Error

Trying to find out Core Data Errors Error, and looking inside userInfo in NSError returned by MOC's save method.
iphone-core-data-unresolved-error-while-saving
I am not able to make commends or raise questions due to my lack of points.
Can any one point out for me where following keys are defined in Apple Doc, NSValidationErrorObject, NSValidationErrorKey...etc?
My understanding is: if CoreData's Error code == NSValidationMultipleErrorsError, then NSError's userInfo(dictionary) will contain all detailed-single-error information, and all those detailed-single-error will be accessible from an Array stored under "NSDetailedErrorsKey" from userInfo.
I just don't see them (NSValidationErrorObject, NSValidationErrorKe...) in Core Data Constants Reference...??? Are they opaque ?
Thanks.
- (BOOL)saveData {
NSError *error;
if (![_sharedManagedObjectContext save:&error]) {
// If Cocoa generated the error...
NSString *message = nil;
if ([[error domain] isEqualToString:#"NSCocoaErrorDomain"]) {
// ...check whether there's an NSDetailedErrors array
NSDictionary *userInfo = [error userInfo];
if ([userInfo valueForKey:#"NSDetailedErrors"] != nil) {
// ...and loop through the array, if so.
NSArray *errors = [userInfo valueForKey:#"NSDetailedErrors"];
for (NSError *anError in errors) {
NSDictionary *subUserInfo = [anError userInfo];
subUserInfo = [anError userInfo];
// Granted, this indents the NSValidation keys rather a lot
// ...but it's a small loss to keep the code more readable.
NSLog(#"Core Data Save Error\n\n \
NSValidationErrorKey\n%#\n\n \
NSValidationErrorPredicate\n%#\n\n \
NSValidationErrorObject\n%#\n\n \
NSLocalizedDescription\n%#",
[subUserInfo valueForKey:#"NSValidationErrorKey"],
[subUserInfo valueForKey:#"NSValidationErrorPredicate"],
[subUserInfo valueForKey:#"NSValidationErrorObject"],
[subUserInfo valueForKey:#"NSLocalizedDescription"]);
}
}
// If there was no NSDetailedErrors array, print values directly
// from the top-level userInfo object. (Hint: all of these keys
// will have null values when you've got multiple errors sitting
// behind the NSDetailedErrors key.
else {
NSLog(#"Core Data Save Error\n\n \
NSValidationErrorKey\n%#\n\n \
NSValidationErrorPredicate\n%#\n\n \
NSValidationErrorObject\n%#\n\n \
NSLocalizedDescription\n%#",
[userInfo valueForKey:#"NSValidationErrorKey"],
[userInfo valueForKey:#"NSValidationErrorPredicate"],
[userInfo valueForKey:#"NSValidationErrorObject"],
[userInfo valueForKey:#"NSLocalizedDescription"]);
}
}
// Handle mine--or 3rd party-generated--errors
else {
NSLog(#"Custom Error: %#", [error localizedDescription]);
}
return NO;
}
return YES;
}
[1]: https://stackoverflow.com/questions/1283960/iphone-core-data-unresolved-error-while-saving
Following is the quoted from #quellish message, thanks #quellish!
Core Data validation errors are defined in CoreDataErrors.h. I am considering asking Apple to move that stuff out of core data and into Foundation, since Key Value Coding really "owns" validation. Validation errors should always have a errorCode value between NSValidationErrorMinimum and NSValidationErrorMaximum as well.
I have an example validation error that may be helpful to you.
Single validation error (only one property failed): Error Domain=NSCocoaErrorDomain Code=1560 "The operation couldn’t be completed. (Cocoa error 1560.)" UserInfo=0x2808ac0 {NSDetailedErrors=(
"Error Domain=NSCocoaErrorDomain Code=1670 \"Name must be John\" UserInfo=0x2805f30 {NSLocalizedDescription=Name must be John}",
"Error Domain=NSCocoaErrorDomain Code=1570 \"The operation couldn\U2019t be completed. (Cocoa error 1570.)\" UserInfo=0x28089c0 {NSValidationErrorObject=<Employee: 0xc003180> (entity: Employee; id: 0xc0031d0 <x-coredata:///Employee/t6FEF17D8-0306-4959-9BFB-4B806E6ED1302> ; da…
see full text
a multiple looks similar, with additional NSErrors in the array that is the value of the userInfo dictionary for the key NSDetailedErrorsKey.
Note that the top level NSError is a single error with the cocoa error domain and error code 1560. That is NSValidationMultipleErrorsError. That error should always contain additional errors under the NSDetailedErrorsKey.
hope that helps!

QuickBlox downloading content receiving QBASIHTTPRequestErrorDomain code 1

I'm using the iOS SDK to access download content from the content module. It seems in the delegate method -(void)completedWithResult:(Result*)result, I can have cases where result.success is YES while result.file would be nil.
-(void)completedWithResult:(Result*)result
{
if (result.success) { // YES here
if ([result isKindOfClass: [QBCFileDownloadTaskResult class]]) {
FileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;
res.file; // This is NULL.
res.errors; // This is an empty NSArray
}
}
}
Console log prints this message:
<QBASIHTTPRequest: 0xc26d200>
headers:(null)
body:
error:Error Domain=QBASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x9f27a50 {NSUnderlyingError=0x9f18300 "The operation couldn’t be completed. Connection reset by peer", NSLocalizedDescription=A connection failure occurred}
Is this normal? I would expect in this case res.success a NO.
Let's try latest version of iOS SDK 1.8
http://quickblox.com/developers/IOS#Framework_changelog:
Here is one big change:
replaced core network library ASIHTTPRequest with AFNetworking

Resources