How to specify localized property list? - ios

I have an ios application which is calling a rest web service. I have created a property list file in my app which contains a dictionary of error codes that will be returned by the server and a corresponding message to show.
I am thinking of having multiple property list files for different languages.
How can i make the app to pick up a specific property list based on locale?

You say that the server is generating an error code and a message.
So I think there are more ways to do it.
First you could send a locale header in your request to the server, so that the server would do all localizations for you (which in my opinion is not as good as solution #2).
So I would prefer the way of letting the server just return error codes and handling the messages on client side.
You could create a language project in xcode, for each language you want to support:
http://www.ibabbleon.com/iphone_app_localization.html#extract
In the localizable.strings file I would do the following:
"RestServiceXYErrorTitle_1" = "Authentication failed";
"RestServiceXYErrorMessage_1" = "Your credentials were wrong";
"RestServiceXYErrorTitle_2" = "Resource not available";
"RestServiceXYErrorMessage_2" = "The resource you requested is no longer available";
....
Then I would take the error code returned by the server, e.g. 1 and put it together with my localization string:
NSString *localizedTitleKey = [NSString stringWithFormat:#"RestServiceXYErrorTitle_%#", errorCode];
NSString *localizedMessageKey = [NSString stringWithFormat:#"RestServiceXYErrorMessage_%#", errorCode];
NSString *errorTitle = NSLocalizedString(localizedTitleKey,#"");
NSString *errorMessage = NSLocalizedString(localizedMessageKey,#"");
I think this would be a good solution

Related

MFMailComposeViewController Large Pdfs attachments get stuck

So I am using MFMailComposeViewController to attach pdf files to an email and send it out using the default iOS mail app set up with an exchange account.
If I send a file with size 4863K it works perfectly. Everything goes off as expected.
If I send a file with size 5688K it seems like its working and gets MFMailComposeResultSent as the result sent back to the delegate.
However, the mail never arrives and when I look in the mail app, I see that it is stuck in the Outbox with an error of:
The server rejected the message
What's super weird is that when I try to resent the message from the outbox, it sends out perfectly fine and gives no further error message.
I am sort of at my wits end and have not the first clue what could be going wrong. Clearly I cannot screw around with apple's code, but there don't seem to be many options with the MFMailComposeViewController that I could possibly have screwed up.
The code is fairly straightforward:
- (void) setAttachments:(NSArray*)attatchments
ofDraft:(MFMailComposeViewController*)draft
{
if (attatchments)
{
for (NSString* path in attatchments)
{
NSData* data = [self getDataForAttachmentPath:path];
NSString* basename = [self getBasenameFromAttachmentPath:path];
NSString* pathExt = [basename pathExtension];
NSString* fileName = [basename pathComponents].lastObject;
NSString* mimeType = [self getMimeTypeFromFileExtension:pathExt];
// Couldn't find mimeType, must be some type of binary data
if (mimeType == nil) mimeType = #"application/octet-stream";
[draft addAttachmentData:data mimeType:mimeType fileName:fileName];
}
}
}
The fact that this works for smaller files implies to me that there is nothing wrong with this code and it is copied out of a cordova plugin that sees pretty wide usage. But for whatever reason, files that are over ~5MB just fail for no apparent reason.
Thanks for your help.
Update
I captured the http traffic and discovered that in the situation where the mail is sent using the MFMailComposeViewController, the POST request has a content-length of 0, which is not allowed, so the server returns a 400 error. When I try to resend the same message from the mail app directly, the content-length is the size expected.
This appears to be a limitation of the MessageUI framework, but I cannot verify that there is a universal limitation imposed by Apple.

How to read the file after sending a file using "GDServiceClient sendTo:" method as attachment?

I'm Using two native iOS Apps to implement Good Dynamic Framework app kinetics, for now I'm successfully able to send a consumer request, received it at producer end and send a reply form producer , received at consumer end. using
sendTo (GDServiceClient) >>>>>>>>>>>>>>> GDServiceDidReceiveFrom
GDServiceClientDidReceiveFrom <<<<<<<<<<< replyTo (GDService).
problem arise when I try to send a pdf file from producer to consumer and read it at the consumer end.
I use the "GDServiceClient sendTo" method to send the file as its attachment. seems like file received by the consumer end successfully. I can see the good
console Xcode log
GTICCConnection: Number of attachments: 1
GTICCConnection: Finished reading data from all attachments 1/1. Last file size: 273459
I received the file path from attachment as "Inbox/BundleID/....../myfile.pdf"
But the Problem is GDFileManger contentsAtPath:fileInboxPath become nil and cannot read the file.
Questions
1.Can any one help me to resolve this issue. Is there a special way to read the file from GD Inbox?
Why GDFileManager always need a valid NSFilePath when create a new file using createFileAtPath: ? it says it encrypt the file and file won't be at the physical path.
I found it. I will reply with a detailed answer in few days. until that,
Before read the file content I use check for file existence like this.
if ([[GDFileManager defaultManager] fileExistsAtPath:fileInboxPath]){
NSData *fileData = [[GDFileManager defaultManager] contentsAtPath:fileInboxPath];
NSLog(#"Filedata: %#",fileData);
NSString *content = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
}
but This if condition fails. After I commented out the line
[[GDFileManager defaultManager] fileExistsAtPath:fileInboxPath]
it starts working.

UIWebview not loading the correct localized version of website

In my app I have a link in the menu that takes the user to our FAQ page online. I'm using a webview to load the page and so far so good.
But the problem is, my online page auto detects the user language and loads the correct localized version of the page.
If I open safari on the simulator and load my url, it gets redirected to the correct localized version of it, but using UIWebview on the app it loads the english (default) language.
I've done some research online, but couldn't find anything related to this matter.
Is there something I can/need to pass in order to the correct localized version to be loaded?
Thanks
EDIT:
I'm currently getting the phone language and passing in the URL, but what I'm looking for is for the UIWebview to behave like safari does, by calling the main URL and having the website choose the version based on your language.
You can get the app supported languages as an array of strings with [[NSBundle mainBundle] localizations]; and compare it with the system language like this:
+ (NSString *)preferredLanguage {
NSString *res = #"en";
NSArray *appSupportedLanguages = [[NSBundle mainBundle] localizations];
NSArray *appleLanguages = [NSLocale preferredLanguages];
if (appleLanguages && appleLanguages.count > 0) {
NSString *shortLangId = [appleLanguages.firstObject substringToIndex:2];
if ([appSupportedLanguages containsObject:shortLangId]) {
res = shortLangId;
}
}
return res;
}
The reason i'm using the shortened version here is that iOS 9 changed some languages' ids and it breaks my app — you should probably make some minor changes here. Nevertheless, this method allows you to get the language id you can use to open the proper FAQ page either like https://.../faq_fr.htm or with some server-side processing like https://...?lang=fr.

Not deleting file from ftp using CFURLDestroyResource method in iphone

I have performed upload,download file from ftp using FTPHelper class. It's working perfectly.The issue generated in delete operation. While I'm deleting file from ftp server, nothing happens!. I don't know where I'm getting wrong. I have refered stackoverflow link to solve delete file from ftp but unable to do that.Below is my code to delete file from ftp.
pragma mark ***** Delete File From FTP
+(void)deleteFileFromFTPforItem:(NSString *) anItem
{
[sharedInstance deleteFileFromFTPforItem:anItem];
}
-(void)deleteFileFromFTPforItem:(NSString *) anItem
{
if (!self.uname || !self.pword) COMPLAIN_AND_BAIL(#"Please set user name and password first");
if (!self.urlString) COMPLAIN_AND_BAIL(#"Please set URL string first");
NSString *baseDeleteURL = [NSString stringWithFormat:#"%#/",self.urlString];
NSString *deleteFilePath = [baseDeleteURL stringByAppendingString:anItem];
CFURLRef deleteURL = (CFURLRef)[[NSURL alloc] initWithString:deleteFilePath];
//SInt32 *errorCode = NULL;
//CFURLDestroyResource(deleteURL, errorCode);
DeleteFile(deleteURL);
CFRelease(deleteURL);
}
static Boolean DeleteFile(CFURLRef urlToDelete)
{
Boolean success = true;
CFURLRef deleteURL = urlToDelete;
SInt32 *errorCode = NULL;
success = CFURLDestroyResource(deleteURL, errorCode);
return success;
}
Please give me a proper solution where am I going wrong.I have surfed lot of things but unable to get proper way to delete file from ftp.I have referred link to upload and download file to/from ftp.Your help would be appreciable.Thanks in advanced
To make a long story short, FTP support in NSURL and CFURL should be considered download-only. I don't think it ever fully worked, and ftp is thoroughly deprecated for any purposes other than anonymous downloads anyway, so it is unlikely to ever be fixed.
You can use other FTP access frameworks, as described in this question:
CFURLDestroyResource is now deprecated in iOS7. Anyone know what to use instead?
but really, you should probably be asking yourself whether using FTP is really the right way to do whatever you're trying to do, as opposed to (for example) WebDAV.

Recover a PDF on iOS from a web service

I have a strange problem with my iOS application that calls a .NET web service to recover a PDF.
The web service does some stuff, and returns a PDF document as a reference of the web service (via an out parameter)
The iOS application call the web service, receives an answer and deals with the XML received.
To begin, the web service just returned a "simple" pdf (created in Word). I test my application and all was running well.
I was happy :). Then, I used Microsoft Report Viewer to really generate the PDF...
So I really implement my web service for create the PDF with ReportViewer (http://msdn.microsoft.com/en-us/library/ms251671(v=vs.80).aspx). The pdf generated was correct, I can open it on my server when it was generated. But when I receive the answer in the iOS application, I can't open it because it was corrupt.
Here is the difference of the XML I receive from the web service :
When I return the pdf generated with Word : http://pastie.org/7982815
When I return the pdf generated with ReportViewer : http://pastie.org/7982811
So the main difference is the image parameter that is one-part with the simple PDF and split with the ReportViewer PDF.
Actually I have no idea why the byte array is split as it, and I don't know what I could do to receive a valid PDF.
Once again, the PDF generated with ReportViewer is good, I can open it on the server, and when I send it by e-mail I can open it on my iPad. The problem comes when the web service returns me the PDF as a byte array...
The "split" image is actually an artifact of the web service trying to parse the image for line separators (ie 0d0a == carriage return / new line). If you're lucky, you can reassemble the image by taking each one of the records, including the 0d0a, and just concatenating them. This may be easier than fixing the real problem, which is that your web service is not sending you a single blob, but trying to parse an image into "lines".
It's ok, I solved my problem by concat all the data contains in the image array.
So, considering the XML I receive from the web service (http://pastie.org/7982811), here is my objective-c code to build the correct NSData (the pdf) :
NSMutableData *concatData = [NSMutableData data];
NSArray *partsData = [result objectForKey:#"image"];
for(NSDictionary *dicPdfDataLine in partsData) { // Foreach parts of data
NSArray *arrayPdfDataLine = [dicPdfDataLine allValues];
NSData *dataLine = [arrayPdfDataLine objectAtIndex:0]; // Get the NSData of the current part part
[concatData appendData:dataLine]; // Concat the data
}

Resources