Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7643 views
1
#include "common.h"
2
#include "mupdf/fitz.h"
3
4
#import "MuAppDelegate.h"
5
6
#ifdef CRASHLYTICS_ENABLE
7
#import <Crashlytics/Crashlytics.h>
8
#endif
9
10
@interface MuAppDelegate () <UINavigationControllerDelegate>
11
@end
12
13
@implementation MuAppDelegate
14
{
15
UIWindow *window;
16
UINavigationController *navigator;
17
MuLibraryController *library;
18
BOOL _isInBackground;
19
}
20
21
- (BOOL) application: (UIApplication*)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions
22
{
23
NSString *filename;
24
25
queue = dispatch_queue_create("com.artifex.mupdf.queue", NULL);
26
27
ctx = fz_new_context(NULL, NULL, ResourceCacheMaxSize);
28
fz_register_document_handlers(ctx);
29
30
#ifdef CRASHLYTICS_ENABLE
31
NSLog(@"Starting Crashlytics");
32
[Crashlytics startWithAPIKey:CRASHLYTICS_API_KEY];
33
#endif
34
35
screenScale = [[UIScreen mainScreen] scale];
36
37
library = [[MuLibraryController alloc] initWithStyle: UITableViewStylePlain];
38
39
navigator = [[UINavigationController alloc] initWithRootViewController: library];
40
[[navigator navigationBar] setTranslucent: YES];
41
[[navigator toolbar] setTranslucent: YES];
42
[navigator setDelegate: self];
43
44
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
45
[window setBackgroundColor: [UIColor grayColor]];
46
[window setRootViewController: navigator];
47
[window makeKeyAndVisible];
48
49
filename = [[NSUserDefaults standardUserDefaults] objectForKey: @"OpenDocumentKey"];
50
if (filename)
51
[library openDocument: filename];
52
53
filename = [launchOptions objectForKey: UIApplicationLaunchOptionsURLKey];
54
NSLog(@"urlkey = %@\n", filename);
55
56
return YES;
57
}
58
59
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
60
{
61
NSLog(@"openURL: %@\n", url);
62
if ([url isFileURL]) {
63
NSString *path = [url path];
64
NSString *dir = [NSString stringWithFormat: @"%@/Documents/", NSHomeDirectory()];
65
path = [path stringByReplacingOccurrencesOfString:@"/private" withString:@""];
66
path = [path stringByReplacingOccurrencesOfString:dir withString:@""];
67
NSLog(@"file relative path: %@\n", path);
68
[library openDocument:path];
69
return YES;
70
}
71
return NO;
72
}
73
74
- (void)applicationDidEnterBackground:(UIApplication *)application
75
{
76
printf("applicationDidEnterBackground!\n");
77
[[NSUserDefaults standardUserDefaults] synchronize];
78
_isInBackground = YES;
79
}
80
81
- (void)applicationWillEnterForeground:(UIApplication *)application
82
{
83
printf("applicationWillEnterForeground!\n");
84
_isInBackground = NO;
85
}
86
87
- (void)applicationDidBecomeActive:(UIApplication *)application
88
{
89
printf("applicationDidBecomeActive!\n");
90
}
91
92
- (void)applicationWillTerminate:(UIApplication *)application
93
{
94
printf("applicationWillTerminate!\n");
95
[[NSUserDefaults standardUserDefaults] synchronize];
96
}
97
98
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
99
{
100
NSLog(@"applicationDidReceiveMemoryWarning");
101
int success = fz_shrink_store(ctx, _isInBackground ? 0 : 50);
102
NSLog(@"fz_shrink_store: success = %d", success);
103
}
104
105
- (void) dealloc
106
{
107
dispatch_release(queue);
108
[library release];
109
[navigator release];
110
[window release];
111
[super dealloc];
112
}
113
114
@end
115
116