Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support for ios files app #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/juce_events/messages/juce_ApplicationBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class JUCE_API JUCEApplicationBase
bool sendCommandLineToPreexistingInstance();
#endif

virtual bool urlOpened(URL& url) { return false; }

private:
//==============================================================================
static JUCEApplicationBase* appInstance;
Expand Down
61 changes: 61 additions & 0 deletions modules/juce_gui_basics/native/juce_ios_Windowing.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ - (void) userNotificationCenter: (UNUserNotificationCenter*) center willPresentN
withCompletionHandler: (void (^)(UNNotificationPresentationOptions options)) completionHandler;
- (void) userNotificationCenter: (UNUserNotificationCenter*) center didReceiveNotificationResponse: (UNNotificationResponse*) response
withCompletionHandler: (void(^)())completionHandler;
- (BOOL) application: (UIApplication *) app openURL: (NSURL *) url options: (NSDictionary<UIApplicationOpenURLOptionsKey, id > *) options;
#endif
#endif

Expand Down Expand Up @@ -172,6 +173,66 @@ - (void) applicationWillResignActive: (UIApplication*) application
appBecomingInactiveCallbacks.getReference(i)->appBecomingInactive();
}

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {

if(!JUCEApplicationBase::getInstance())
{
[self applicationDidFinishLaunching:application];
}

NSUInteger accessOptions = NSFileCoordinatorReadingWithoutChanges;

auto *fileAccessIntent = [NSFileAccessIntent readingIntentWithURL:url options:accessOptions];

NSArray<NSFileAccessIntent *> *intents = @[fileAccessIntent];

auto *fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];

[fileCoordinator coordinateAccessWithIntents:intents queue:[NSOperationQueue mainQueue] byAccessor:^(NSError *err) {
if (err == nil) {
[url startAccessingSecurityScopedResource];

NSError *error = nil;

NSData *bookmark = [url bookmarkDataWithOptions:0
includingResourceValuesForKeys:nil
relativeToURL:nil
error:&error];

[bookmark retain];

[url stopAccessingSecurityScopedResource];

URL juceUrl(nsStringToJuce([url absoluteString]));

if (error == nil) {
setURLBookmark(juceUrl, (void *) bookmark);
} else {
auto *desc = [error localizedDescription];
ignoreUnused(desc);
jassertfalse;
}

if (auto *app = JUCEApplicationBase::getInstance())
{
app->urlOpened(juceUrl);
}
else
{
jassertfalse;
}
} else {
auto *desc = [err localizedDescription];
ignoreUnused(desc);
jassertfalse;
}
}];

return YES;
}

- (void) application: (UIApplication*) application handleEventsForBackgroundURLSession: (NSString*)identifier
completionHandler: (void (^)(void))completionHandler
{
Expand Down