Using dropbox chooser to import pdf in ipad app - ios

Hello i'm building a iPad app in which i want to use dropbox to get my pdf files in my application. Now i've tried the dropbox sdk but didn't get it working. I've seen they have a special dropbox chooser but only in web. The basic idea is to get a chooser in which i can chose the pdf which i want to read in my custom ipad reader. My question is if anybody has already done this before or if anybody have some suggestions where i can start?

Well you dont need any special chooser module. Dropbox API is very rich in terms of selecting files with its types. Use this code
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
NSMutableArray *pathArray = [[NSMutableArray alloc] init];
for (DBMetadata *child in metadata.contents) {
if (!child.isDirectory) {
NSString *fileExtension = [[child.filename componentsSeparatedByString:#"."] lastObject];
if ([fileExtension compare:#"pdf" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
[pathArray addObject:child];
}
}
else {
[pathArray addObject:child];
}
}
}
This pathArray contains the list of PDF files only. Check it out and let me know if you are not getting anything. Have a Happy Coding.!! Cheers.!!

Related

UI automation testing with multilanguage in iOS

I've written some UI tests in Xcode 7 and when I need to refer to a button I use its accessibility.identifier. This logic worked correctly for all the languages.
app.buttons["signin"].tap()
With Xcode 7.3 when I try to launch this code the test fails because the button cannot be found if the simulator language is not English. I've also tried to record the navigation to check how Xcode reads this button when language is different by English and I found out that it use the translations as key... it doesn't make any sense at all!
Those test were really useful to create screenshots... but obviously with this issue I cannot run tests (and create screens) for all the languages.
How can I point to a button in absolute way if it cannot be recognized by identifier!?
----EDIT
I found the main issue. The company that did the translation has translated the labelidentifier fields :/
I'm trying to get the element using app.buttons.elementBoundByIndex(1) but it doesn't seem to work correctly
Accessibility identifiers should not be localized strings, otherwise they will change when you are running your app in a different language.
Just hard-code the accessibility identifiers to make them persistent regardless of language.
button.accessibilityIdentifier = "myButton"
You can have actual accessibilityIdentifier assigned to button and then try accessing it. Accessing buttons with text is always a bad idea as text may change anytime.
E.g. : XCUIApplication().buttons["AppSignInIdentifier"]
I hope your project is maintaining the localization file. I faced the same issue. If so then localization doesn't work directly with UIAutomation yet.
There is a workaround for this, I am sharing the code snippet with you.
You need to find out the xcodeproj file in your bundle first. As these files are not bundled in the UIAutomation target.
- (NSString *)getLocalizedString:(NSString *)string withComments:(NSString *)comments {
NSString *userLocale = [[NSLocale currentLocale] localeIdentifier];
NSString *userLanguage = [userLocale substringToIndex:2];
NSString *path = [self getProjectPath];
path = [path stringByAppendingPathComponent:[NSString stringWithFormat:#"/YourProjectFileName/Resources/Localization/%#.lproj",userLanguage]];
NSBundle *bundle = [NSBundle bundleWithPath:path];
NSString *localizedString = NSLocalizedStringFromTableInBundle(string, #"Localizable", bundle, comments);
return localizedString;
}
- (NSString *)getProjectPath {
NSString *currentSourceFilePath = [[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] stringByDeletingLastPathComponent];
NSString *currentPath = [currentSourceFilePath copy];
BOOL foundIt = NO;
do {
NSString *testPath = [currentPath stringByAppendingPathComponent:#"XYZ.xcodeproj"];
if ([[NSFileManager defaultManager] fileExistsAtPath:testPath]) {
// found it
foundIt = YES;
break;
}
if ([currentPath isEqualToString:#"/"]) {
// cannot go further up
break;
}
currentPath = [currentPath stringByDeletingLastPathComponent];
} while ([currentPath length]);
if (!foundIt) {
return nil;
}
return currentPath;
}
And to use this //
NSString *loginStr = [self getLocalizedString:#"Login" withComments:#""];
And moreover for the better use of Automation, please set the accessibility labels for your controls, so that it would be easy for the automation process to find out that, which is less overhead on processor and less prone to crashes and issues.

skobbler can i cache json data?

I'm using skobbler and skmaps for an app that download for offline use some regions of the map. I'm using the code i have found in the example of the framework package, in this case
MapJSONViewController
MapDownloadViewController
I have implemented also the app delegate code, so every time i start the app, it download and parse a json of about 1mb
- (void)mapsVersioningManager:(SKMapsVersioningManager *)versioningManager loadedWithMapVersion:(NSString *)currentMapVersion
{
[[XMLParser sharedInstance] downloadAndParseJSON];
}
It's possible to avoid this behaviour? I don't want to download 1mb of json data every app init if not necessary... Maybe i can download and include a physic map json file in my app to have a start version ? Or this "local behaviour" will bring my app to work with an outdated json version very soon? Maybe another behaviour is to maintain a local version with a data and redownload it only once a week for example... It seems at me a common problem, there's someone how achive a convenient behaviour?
Yes, you can include the json file in your app & read it from disk.
In the XMLParser.m replace the code in downloadAndParseJson with:
- (void)downloadAndParseJSON
{
[self parseJSON];
NSString *libraryFolderPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSLog(#"%#",libraryFolderPath);
}
and parseJSON with:
- (void)parseJSON
{
NSString *jsonString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Maps" ofType:#"json"] encoding:NSUTF8StringEncoding error:nil];
SKTMapsObject *skMaps = [SKTMapsObject convertFromJSON:jsonString];
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate setSkMapsObject:skMaps];
self.isParsingFinished = YES;
[[NSNotificationCenter defaultCenter]postNotificationName:kParsingFinishedNotificationName object:nil];
}
Here you can find a modified demo project that reads the Maps.json file from resources (the .json file is included in the resources folder).

how to generate qr code image, with vcf file ios

i have contact details as string
BEGIN:VCARD
VERSION:3.0
N:Doe;John
FN:John Doe
ORG:Company
TITLE:CEO
ADR;TYPE=WORK:;;1234 Any Street;Beverly Hills;CA;90210;USA
TEL;TYPE=WORK,VOICE:1-555-555-4321
TEL;TYPE=CELL,VOICE:1-555-555-1234
EMAIL;TYPE=PREF,INTERNET:johndoe#yourcompany.com
URL;TYPE=WORK:http://yourcompany.com
END:VCARD
how to make qr code image with above mention information, programmatically.
i ended up find my own solution,using Zxing libary
ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
NSString *str=#"BEGIN:VCARD\r\nVERSION:2.1\r\nN:Satya;Dash;;;\r\nADR;DOM;PARCEL;HOME:;;****Mission Street;Cuttack City;Orissa;94014;INDIA.\r\nEMAIL;INTERNET:satya#domain.com\r\nTEL;CELL:22-122-4567\r\nTEL;CELL:133-156-3345\r\nEND:VCARD";
ZXBitMatrix* result = [writer encode:str
format:kBarcodeFormatQRCode
width:320
height:300
error:&error];
if (result) {
UIImage* uiImage = [[UIImage alloc] initWithCGImage:[[ZXImage imageWithMatrix:result] cgimage]];
[self.imageView setImage:uiImage];
[self.lbl setText:[NSString stringWithFormat:#"%#",str]];
} else {
NSString *errorMessage = [error localizedDescription];
NSLog(#"error is %#",errorMessage);
}
when you will scan qr image it will return vcard version 2.1
I m using codeignitor for this.This is the library link (https://github.com/dwisetiyadi/CodeIgniter-PHP-QR-Code).i insert a short url in this.generated by yourls(yourls.org/#API).when user scans the code.mobile ask to open the link and when user opens the link.i take him to my webpage where whole qr code vcf information is shown link name address etc and a download button.when user click on download button (.vcf) file is gets download which can be used in mobile as well as outlook.

Open a pdf saved in my documents folder in Xcode project

I have made an app that creates a pdf and stores it in the apps documents folder. I would now like to open it and view it from within the app when a 'View pdf' UIButton is pressed.
I have already looked at a few questions on here and I have considered either a separate view controller or perhaps a scroll view.
What is the best method to use?
UPDATE:
I have followed advice and I am trying to use QLPreviewController. I have added QuickLook framework and now have the following, but I am stuck on how to get the path recognised in the pathForResource. Any suggestions?
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
NSString *path=[[NSBundle mainBundle] pathForResource:[pdfPathWithFileName] ofType:nil];
return [NSURL fileURLWithPath:path];
}
- (IBAction)viewPdfButton:(id)sender {
NSString *filename= #"ObservationPDF.pdf";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documnetDirectory = [path objectAtIndex:0];
NSString *pdfPathWithFileName = [documnetDirectory stringByAppendingPathComponent:filename];
[self generatePdf: pdfPathWithFileName];
QLPreviewController *previewController=[[QLPreviewController alloc]init];
previewController.delegate=self;
previewController.dataSource=self;
[self presentViewController:previewController animated:YES completion:nil];
}
If the PDF file is in the app documents folder then you shouldn't be thinking about passing it to another app, you should be looking to present the file inside the app. 2 general options:
Add a UIWebView and load the local file into it
Use QLPreviewController to show a new view containing the PDF
The web view is simple and requires no transition on the UI. The preview controller needs a transition but offers some sharing / printing support for free.
This line is confused (and invalid syntax by the looks of it):
NSString *path=[[NSBundle mainBundle] pathForResource:[pdfPathWithFileName] ofType:nil];
You only use NSBundle to get items out of the bundle, and that isn't what you have. You should just be creating the URL with the file path where you save the file:
[NSURL fileURLWithPath:pdfPathWithFileName];
(which you may store or you may need to recreate in the same way as when you save the file)

Xcode with VFR Reader loading PDF mistake

I use vfr/reader to open PDF files. When I open first PDF file my app opens it correctly but when I open another one, my app opens the first file again.
This is my function to read PDF file
-(void)readIssue:(IssueMath *)issue {
NSString *filePath = [[issue.contentURL path] stringByAppendingPathComponent:#"Mathematics.pdf"];
NSLog(#"Read Path 1: %# ",filePath);
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:nil];
NSLog(#"Read Path 2: %# ",document.fileURL);
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self; // Set the ReaderViewController delegate to self
readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:readerViewController animated:YES];
}
And this is NSLog output:
2012-11-02 20:09:31.081 MAGAZINE[314:15203] Read Path 1: /Users/eakmotion/Library/Application Support/iPhone Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE3_2011/Mathematics.pdf
2012-11-02 20:09:31.109 MAGAZINE[314:15203] Read Path 2: file://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE2_2011/Mathematics.pdf
I want to read "ISSUE3_2011/Mathematics.pdf" but app still reads first path "ISSUE2_2011/Mathematics.pdf"
Why filePath is still the same?
How can I solve this problem?
Yeah your solution works but if you want to keep track of your all pdf documents (ex. current page no)
You have to give unique names for your local pdf files.. Because it will search for Mathematics.plist file on local device folder to read the current page number..
/Users/eakmotion/Library/Application Support/iPhone Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE3_2011/Mathematics.pdf
file://localhost/Users/eakmotion/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/EC25BC08-E1E7-44B6-9AD8-0A321EEAC8B6/Library/Caches/ISSUE2_2011/Mathematics.pdf
these files are looking for the same Mathematics.plist file
in the class ReaderDocument "unarchiveFromFileName" method
NSString *archivePath = [ReaderDocument applicationSupportPath]; // Application's "~/Library/Application Support" path
NSString *archiveName = [[filename stringByDeletingPathExtension] stringByAppendingPathExtension:#"plist"];
try to modify this code section or give your files unique names like Mathematics_ISSUE3_2011.pdf and Mathematics_ISSUE2_2011.pdf
I know this question is quite a few months old, but just in case anyone is experiencing this same issue (as myself), I have found a solution for it.
In the vfr/Reader's source, locate the Sources/ReaderDocument.m file, and look for a function named + (ReaderDocument *)withDocumentFilePath:.
There, comment out the conditional which prevents the document from reloading as shown below.
+ (ReaderDocument *)withDocumentFilePath:(NSString *)filePath password:(NSString *)phrase
{
ReaderDocument *document = nil; // ReaderDocument object
document = [ReaderDocument unarchiveFromFileName:filePath password:phrase];
//if (document == nil) // Unarchive failed so we create a new ReaderDocument object
//{
document = [[ReaderDocument alloc] initWithFilePath:filePath password:phrase];
//}
return document;
}
This was my quick and dirty approach to get documents to reload. The caveat to this solution is that the pdf reader won't keep track of where you left off in your pdf pages, which in my app, was not of importance.
I was facing the same problem and found following solution:
// Path to first PDF file
NSString *filePath =
[[NSBundle mainBundle] pathForResource:#"someBookeName" ofType:#"pdf"];
Just change the file path like shown above. As you can see, now you don't need NSArray * PDF.

Resources