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

Mobile deep link #813

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
46 changes: 43 additions & 3 deletions modules/juce_gui_basics/native/juce_ios_Windowing.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,62 @@ - (void) dealloc
[super dealloc];
}

- (void) applicationDidFinishLaunching: (UIApplication*) application
{
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ignoreUnused (application);
initialiseJuce_GUI();

if (auto* app = JUCEApplicationBase::createInstance())
{
if (! app->initialiseApp())
exit (app->shutdownApp());
{
exit(app->shutdownApp());
return NO;
}
}
else
{
jassertfalse; // you must supply an application object for an iOS app!
}

return YES;
}

- (BOOL) application: (UIApplication*) application willFinishLaunchingWithOptions: (NSDictionary<UIApplicationLaunchOptionsKey, id>*) launchOptions
{
return YES;
}

-(BOOL) application: (UIApplication*) application continueUserActivity: (NSUserActivity*) userActivity restorationHandler: (void (^)(NSArray * _Nullable)) restorationHandler
{
// Check whether the activity was from a web page redirect to the app.
if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb]) {
// Get the URL from the UserActivty Object.
NSURL *url = userActivity.webpageURL;

if (auto* app = JUCEApplicationBase::getInstance())
{
auto commandLine (nsStringToJuce ([url absoluteString]));
app->anotherInstanceStarted (commandLine);
return YES;
}
}
return NO;
}

- (BOOL) application: (UIApplication*) application openURL: (NSURL*) url sourceApplication: (NSString*) sourceApplication annotation: (id) annotation {

if (auto* app = JUCEApplicationBase::getInstance())
{
auto commandLine (nsStringToJuce ([url absoluteString]));
app->anotherInstanceStarted (commandLine);
return YES;
}

return NO;
}


- (void) applicationWillTerminate: (UIApplication*) application
{
ignoreUnused (application);
Expand Down
37 changes: 37 additions & 0 deletions modules/juce_gui_extra/native/juce_android_PushNotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,39 @@ struct PushNotifications::Pimpl
&& env->CallBooleanMethod (extras, AndroidBundle.containsKey, javaString ("google.message_id").get());
}

static bool isBrowsableNotificationIntent (jobject intent)
{
auto* env = getEnv();

auto intentAction = juceString ((jstring) env->CallObjectMethod (intent, AndroidIntent.getAction));

auto isView = intentAction == "android.intent.action.VIEW";

auto categories = LocalRef<jobject> (env->CallObjectMethod (intent, AndroidIntent.getCategories));

int categoriesNum = categories != nullptr
? env->CallIntMethod (categories, JavaSet.size)
: 0;

if (categoriesNum == 0)
return false;

if (! env->CallBooleanMethod (categories, JavaSet.contains, javaString ("android.intent.category.BROWSABLE").get()))
return false;

return isView;
}

static void callAnotherInstanceStartedWithIntentURI (jobject intent)
{
auto* env = getEnv();

auto intentDataUri = LocalRef<jobject> (env->CallObjectMethod (intent, AndroidIntent.getData));
auto intentDataString = juceString ((jstring) env->CallObjectMethod (intentDataUri, AndroidUri.toString));

JUCEApplication::getInstance()->anotherInstanceStarted (intentDataString);
}

PushNotifications& owner;
};

Expand Down Expand Up @@ -1632,6 +1665,10 @@ bool juce_handleNotificationIntent (void* intent)

return true;
}
else if (PushNotifications::Pimpl::isBrowsableNotificationIntent ((jobject) intent))
{
return true;
}
#if defined(JUCE_FIREBASE_MESSAGING_SERVICE_CLASSNAME)
else if (PushNotifications::Pimpl::isRemoteNotificationIntent ((jobject) intent))
{
Expand Down