diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-04-27 15:15:43 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-04-27 15:15:43 +0200 |
commit | ed8a8ec279324c9f7edf3e61ada42e4dda70d469 (patch) | |
tree | 1e6d6acae4399cce580124276850672d7fdd7fdb /ios | |
parent | af5a6088a3c3e4d61f84d2c93a8968c04069864d (diff) | |
download | mupdf-ed8a8ec279324c9f7edf3e61ada42e4dda70d469.tar.xz |
Register iOS app as handler for PDF, XPS and CBZ files.
Diffstat (limited to 'ios')
-rw-r--r-- | ios/Info.plist | 83 | ||||
-rw-r--r-- | ios/main.m | 46 |
2 files changed, 120 insertions, 9 deletions
diff --git a/ios/Info.plist b/ios/Info.plist index 6afbcf12..1e29c114 100644 --- a/ios/Info.plist +++ b/ios/Info.plist @@ -48,5 +48,88 @@ <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> + <key>CFBundleDocumentTypes</key> + <array> + <dict> + <key>CFBundleTypeName</key> + <string>PDF</string> + <key>LSItemContentTypes</key> + <array> + <string>com.adobe.pdf</string> + </array> + <key>LSHandlerRank</key> + <string>Alternate</string> + </dict> + <dict> + <key>LSItemContentTypes</key> + <array> + <string>com.microsoft.xps</string> + </array> + <key>CFBundleTypeName</key> + <string>XPS</string> + <key>LSHandlerRank</key> + <string>Alternate</string> + </dict> + <dict> + <key>CFBundleTypeName</key> + <string>CBZ</string> + <key>LSItemContentTypes</key> + <array> + <string>public.zip-archive</string> + </array> + <key>LSHandlerRank</key> + <string>Alternate</string> + </dict> + </array> + <key>UTImportedTypeDeclarations</key> + <array> + <dict> + <key>UTTypeConformsTo</key> + <array> + <string>public.data</string> + </array> + <key>UTTypeIdentifier</key> + <string>com.microsoft.xps</string> + <key>UTTypeTagSpecification</key> + <dict> + <key>public.filename-extension</key> + <array> + <string>xps</string> + <string>oxps</string> + </array> + </dict> + </dict> + <dict> + <key>UTTypeConformsTo</key> + <array> + <string>public.data</string> + </array> + <key>UTTypeIdentifier</key> + <string>public.zip-archive</string> + <key>UTTypeTagSpecification</key> + <dict> + <key>public.filename-extension</key> + <array> + <string>zip</string> + <string>cbz</string> + </array> + </dict> + </dict> + <dict> + <key>UTTypeConformsTo</key> + <array> + <string>public.data</string> + </array> + <key>UTTypeIdentifier</key> + <string>com.adobe.pdf</string> + <key>UTTypeTagSpecification</key> + <dict> + <key>public.filename-extension</key> + <array> + <string>pdf</string> + </array> + </dict> + </dict> + </array> </dict> </plist> @@ -272,10 +272,10 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, - (void) viewWillAppear: (BOOL)animated { - [self setTitle: @"PDF and XPS Documents"]; + [self setTitle: @"PDF, XPS and CBZ Documents"]; [self reload]; printf("library viewWillAppear (starting reload timer)\n"); - timer = [NSTimer timerWithTimeInterval: 1 + timer = [NSTimer timerWithTimeInterval: 3 target: self selector: @selector(reload) userInfo: nil repeats: YES]; [[NSRunLoop currentRunLoop] addTimer: timer forMode: NSDefaultRunLoopMode]; @@ -290,18 +290,26 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, - (void) reload { - NSError *error = nil; - if (files) { [files release]; files = nil; } + NSFileManager *fileman = [NSFileManager defaultManager]; NSString *docdir = [NSString stringWithFormat: @"%@/Documents", NSHomeDirectory()]; - files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: docdir error: &error]; - if (error) - files = [NSArray arrayWithObjects: @"...error loading directory...", nil]; - [files retain]; + NSMutableArray *outfiles = [[NSMutableArray alloc] init]; + NSDirectoryEnumerator *direnum = [fileman enumeratorAtPath:docdir]; + NSString *file; + BOOL isdir; + while (file = [direnum nextObject]) { + NSString *filepath = [docdir stringByAppendingPathComponent:file]; + NSLog(@"file %@\n", file); + if ([fileman fileExistsAtPath:filepath isDirectory:&isdir] && !isdir) { + [outfiles addObject:file]; + } + } + + files = outfiles; [[self tableView] reloadData]; } @@ -1386,6 +1394,8 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, - (BOOL) application: (UIApplication*)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions { + NSString *filename; + queue = dispatch_queue_create("com.artifex.mupdf.queue", NULL); // use at most 128M for resource cache @@ -1405,13 +1415,31 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, [window addSubview: [navigator view]]; [window makeKeyAndVisible]; - NSString *filename = [[NSUserDefaults standardUserDefaults] objectForKey: @"OpenDocumentKey"]; + filename = [[NSUserDefaults standardUserDefaults] objectForKey: @"OpenDocumentKey"]; if (filename) [library openDocument: filename]; + filename = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey]; + NSLog(@"urlkey = %@\n", filename); + return YES; } +- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation +{ + NSLog(@"openURL: %@\n", url); + if ([url isFileURL]) { + NSString *path = [url path]; + NSString *dir = [NSString stringWithFormat: @"%@/Documents/", NSHomeDirectory()]; + path = [path stringByReplacingOccurrencesOfString:@"/private" withString:@""]; + path = [path stringByReplacingOccurrencesOfString:dir withString:@""]; + NSLog(@"file relative path: %@\n", path); + [library openDocument:path]; + return YES; + } + return NO; +} + - (void)applicationDidEnterBackground:(UIApplication *)application { printf("applicationDidEnterBackground!\n"); |