Permalink
Browse files

Update Kiosk Code to support Open In...

  • Loading branch information...
steipete committed Mar 4, 2014
1 parent e3f8567 commit 41c000fe87a6fd9144c7b50a4a4dc052fa466bac
@@ -342,12 +342,18 @@ - (NSMutableArray *)searchFolder:(NSString *)sampleFolder {
- (NSMutableArray *)searchForMagazineFolders {
NSMutableArray *folders = [NSMutableArray array];
+ // Add Samples
NSString *sampleFolder = [NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"Samples"];
[folders addObjectsFromArray:[self searchFolder:sampleFolder]];
+ // Add downloaded files
NSString *dirPath = [PSCStoreManager.storagePath stringByAppendingPathComponent:@"downloads"];
[folders addObjectsFromArray:[self searchFolder:dirPath]];
+ // Add files from Open In...PSPDFFileManager.defaultManager.documentDirectory
+ NSString *documentsFolder = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
+ [folders addObjectsFromArray:[self searchFolder:documentsFolder]];
+
// flatten hierarchy
if (PSPDFStoreManagerPlain) {
// if we don't have any folders, create one
@@ -112,9 +112,9 @@ - (void)createTableContent {
// Playground is convenient for testing.
[appSection addContent:[PSContent contentWithTitle:@"PSPDFViewController playground" contentDescription:@"Simple Test-Bed for the PSPDFViewController" block:^{
PSPDFDocument *document;
- document = [PSCAssetLoader sampleDocumentWithName:kHackerMagazineExample];
- //document = [PSPDFDocument documentWithURL:[samplesURL URLByAppendingPathComponent:@"Testcase_Rotated_Complex_Form.pdf"]];
- //document = [PSPDFDocument documentWithURL:[samplesURL URLByAppendingPathComponent:@"Testcase_Wartungsformular_2.pdf"]];
+ //document = [PSCAssetLoader sampleDocumentWithName:kHackerMagazineExample];
+ document = [PSPDFDocument documentWithURL:[samplesURL URLByAppendingPathComponent:@"Testcase_Rotated_Complex_Form.pdf"]];

This comment has been minimized.

Show comment Hide comment
@matej

matej Mar 6, 2014

Contributor

Has this document been added? I get the following error.

2014-03-06 11:30:37.090 PSPDFCatalog[38132:70b] Warning: -[PSPDFDocumentProvider requestDocumentRefWithOwner:]/338 File at /Users/matej/Library/Application Support/iPhone Simulator/7.0.3/Applications/F2469FCF-5105-4739-8ACD-51B9D8BD40E6/PSPDFCatalog.app/Samples/Testcase_Rotated_Complex_Form.pdf does not exist.
@matej

matej Mar 6, 2014

Contributor

Has this document been added? I get the following error.

2014-03-06 11:30:37.090 PSPDFCatalog[38132:70b] Warning: -[PSPDFDocumentProvider requestDocumentRefWithOwner:]/338 File at /Users/matej/Library/Application Support/iPhone Simulator/7.0.3/Applications/F2469FCF-5105-4739-8ACD-51B9D8BD40E6/PSPDFCatalog.app/Samples/Testcase_Rotated_Complex_Form.pdf does not exist.
+ //document = [PSPDFDocument documentWithURL:[samplesURL URLByAppendingPathComponent:@"CMYK-image-mokafive.pdf"]];
PSPDFViewController *controller = [[PSCKioskPDFViewController alloc] initWithDocument:document];
controller.statusBarStyleSetting = PSPDFStatusBarStyleDefault;
@@ -2,16 +2,18 @@
// PSCAppDelegate.h
// PSPDFKiosk
//
-// Created by Peter Steinberger on 12/14/12.
-// Copyright (c) 2012 PSPDFKit. All rights reserved.
+// Copyright (c) 2012-2014 PSPDFKit GmbH. All rights reserved.
+//
+// The PSPDFKit Sample applications are licensed with a modified BSD license.
+// Please see License for details. This notice may not be removed from this file.
//
#import <UIKit/UIKit.h>
@class PSCGridViewController;
@interface PSCAppDelegate : UIResponder <UIApplicationDelegate>
-@property (strong, nonatomic) UIWindow *window;
-@property (strong, nonatomic) PSCGridViewController *viewController;
+@property (nonatomic, strong) UIWindow *window;
+@property (nonatomic, strong) UINavigationController *navigationController;
@end
@@ -2,51 +2,85 @@
// PSCAppDelegate.m
// PSPDFKiosk
//
-// Created by Peter Steinberger on 12/14/12.
-// Copyright (c) 2012 PSPDFKit. All rights reserved.
+// Copyright (c) 2012-2014 PSPDFKit GmbH. All rights reserved.
+//
+// The PSPDFKit Sample applications are licensed with a modified BSD license.
+// Please see License for details. This notice may not be removed from this file.
//
#import "PSCAppDelegate.h"
#import "PSCGridViewController.h"
@interface UIColor (PSPDFCatalogAdditions)
-+ (UIColor *)pspdfColor;
++ (UIColor *)psc_mainColor;
@end
-
@implementation PSCAppDelegate
+///////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark - UIApplicationDelegate
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
[UIApplication.sharedApplication setStatusBarStyle:UIStatusBarStyleDefault];
PSCGridViewController *gridController = [PSCGridViewController new];
- UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:gridController];
+ UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:gridController];
if (PSCIsUIKitFlatMode()) {
PSC_IF_IOS7_OR_GREATER([UIApplication.sharedApplication setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
- navController.navigationBar.barTintColor = UIColor.pspdfColor;
- navController.toolbar.tintColor = UIColor.blackColor;
- navController.view.tintColor = UIColor.whiteColor;
+ navigationController.navigationBar.barTintColor = UIColor.psc_mainColor;
+ navigationController.toolbar.tintColor = UIColor.blackColor;
+ navigationController.view.tintColor = UIColor.whiteColor;
// By default the system would show a white cursor.
- [[UITextField appearance] setTintColor:UIColor.pspdfColor];
- [[UITextView appearance] setTintColor:UIColor.pspdfColor];
- [[UISearchBar appearance] setTintColor:UIColor.pspdfColor];)
- navController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : UIColor.whiteColor};
+ [[UITextField appearance] setTintColor:UIColor.psc_mainColor];
+ [[UITextView appearance] setTintColor:UIColor.psc_mainColor];
+ [[UISearchBar appearance] setTintColor:UIColor.psc_mainColor];)
+ navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : UIColor.whiteColor};
}else {
[UIApplication.sharedApplication setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
}
- self.window.rootViewController = navController;
+ self.navigationController = navigationController;
+ self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
+
+ // Opened with the Open In... feature?
+ [self handleOpenURL:launchOptions[UIApplicationLaunchOptionsURLKey]];
+
return YES;
}
+- (BOOL)application:(UIApplication *)application openURL:(NSURL *)URL sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
+ NSLog(@"Open %@ from %@ (annotation: %@)", URL, sourceApplication, annotation);
+ [PSCStoreManager.sharedStoreManager loadMagazinesFromDisk]; // triffer refresh
+ return [self handleOpenURL:URL];
+}
+
+- (BOOL)handleOpenURL:(NSURL *)launchURL {
+ // Directly open the PDF.
+ if (launchURL.isFileURL && [NSFileManager.defaultManager fileExistsAtPath:launchURL.path]) {
+ PSPDFDocument *document = [PSPDFDocument documentWithURL:launchURL];
+ PSPDFViewController *pdfController = [self viewControllerForDocument:document];
+ [self.navigationController popToRootViewControllerAnimated:NO];
+ [self.navigationController pushViewController:pdfController animated:NO];
+ return YES;
+ }
+ return NO;
+}
+
+- (PSPDFViewController *)viewControllerForDocument:(PSPDFDocument *)document {
+ PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
+ pdfController.rightBarButtonItems = @[pdfController.searchButtonItem, pdfController.outlineButtonItem, pdfController.annotationButtonItem, pdfController.viewModeButtonItem];
+ pdfController.additionalBarButtonItems = @[pdfController.openInButtonItem, pdfController.bookmarkButtonItem, pdfController.brightnessButtonItem, pdfController.printButtonItem, pdfController.emailButtonItem];
+ return pdfController;
+}
+
@end
@implementation UIColor (PSPDFCatalogAdditions)
-+ (UIColor *)pspdfColor {
++ (UIColor *)psc_mainColor {
return [UIColor colorWithRed:0.f green:166.f/255.f blue:240.f/255.f alpha:1.f];
}

0 comments on commit 41c000f

Please sign in to comment.