Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

launch on pgp file

roryclear0e660d7298f7
diff --git a/clearcam/SceneDelegate.m b/clearcam/SceneDelegate.m
index e9dfa98..30ca4c7 100644
--- a/clearcam/SceneDelegate.m
+++ b/clearcam/SceneDelegate.m
@@ -1,27 +1,50 @@
#import "SceneDelegate.h"
+#import "ViewController.h" // Import your main view controller
#import <UIKit/UIKit.h>
@interface SceneDelegate () <UIDocumentInteractionControllerDelegate>
@property (strong, nonatomic) UIDocumentInteractionController *docController;
+@property (strong, nonatomic) NSURL *pendingURL; // Store the URL if the app is launched from scratch
@end
@implementation SceneDelegate
-// This method will be called when your app is opened with a URL (e.g., a .pgp file)
+- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
+ // Set up the window and root view controller
+ self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
+
+ // Set the root view controller to your main ViewController
+ ViewController *rootViewController = [[ViewController alloc] init];
+ UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
+ self.window.rootViewController = navigationController;
+ [self.window makeKeyAndVisible];
+
+ // Check if the app was launched with a URL (e.g., opening a .pgp file)
+ if (connectionOptions.URLContexts.count > 0) {
+ NSURL *url = connectionOptions.URLContexts.anyObject.URL;
+ if ([url.pathExtension isEqualToString:@"pgp"]) {
+ // Store the URL for later use
+ self.pendingURL = url;
+
+ // Handle the pending URL after a slight delay to ensure the window is set up
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ [self handlePGPFileAtURL:self.pendingURL];
+ self.pendingURL = nil; // Clear the pending URL
+ });
+ }
+ }
+}
+
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
- // Get the URL of the opened file
+ // Handle the URL when the app is already running
NSURL *url = URLContexts.anyObject.URL;
-
- // Check if the file has a .pgp extension
if ([url.pathExtension isEqualToString:@"pgp"]) {
- // Handle the .pgp file (e.g., decrypt or process it)
[self handlePGPFileAtURL:url];
}
}
-// Custom method to handle the .pgp file and open "image.jpg" from the documents folder
- (void)handlePGPFileAtURL:(NSURL *)url {
// Get the path to the app's documents directory
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject;
@@ -31,10 +54,6 @@
// Check if the file exists at the path
if ([[NSFileManager defaultManager] fileExistsAtPath:imageURL.path]) {
- // Get the root view controller of the window to present the document controller
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
- UIViewController *rootViewController = window.rootViewController;
-
// Create a UIDocumentInteractionController for the image file
self.docController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
@@ -49,11 +68,17 @@
}
}
-// Implementing the required delegate method
+#pragma mark - UIDocumentInteractionControllerDelegate
+
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
- // Return the view controller that will present the preview
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
- return window.rootViewController;
+ // Return the root view controller to present the preview
+ return self.window.rootViewController;
+}
+
+- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
+ // This method is called when the user is done viewing the image
+ // You can add any cleanup or navigation logic here if needed
+ NSLog(@"User is done viewing the image.");
}
@end