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

iOS deep linking #396

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

iOS deep linking #396

wants to merge 15 commits into from

Conversation

KennyHuRadar
Copy link
Contributor

@KennyHuRadar KennyHuRadar commented Oct 1, 2024

This PR adds deep linking support to the SDK.

Dashboard Setup

From the dashboard, an user should configure the geofence metadata to include the key value pair for radar:notificationURL

image

SDK setup

Automatic Setup

The user can also perform the following to have setup done automatically

radarInitializeOptions.autoHandleNotificationDeepLinks = true
Radar.initialize(publishableKey: "prj_test_pk_000", options: radarInitializeOptions )

Manual Setup

If the user does not wish to use the automatic setup, the user should implement

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
        Radar.handleURLFromNotification(response.notification)
    }

Handling URL links in app

RadarURLDelegate

RadarURLDelegate is a light weight way to handle the URL navigation in app.

To handle the deep link URL, one can implement RadarURLDelegate to handle the URL that is passed down by the on premise notification.

class AppDelegate: UIResponder, UIApplicationDelegate, RadarURLDelegate ... {
    
    func didHandleURL(_ url: URL) -> Bool {
        print(" called with url %@", url)
        // handle navigation here
        //return if the URL was successfully handled
        return true
    }

It is optional to implement RadarURLDelegate and to set the radarInitializeOptions.urlDelegate to YES.

Default iOS setup

If the radarInitializeOptions.urlDelegate is not defined or returns false, we will default to calling [application openURL:url options:@{} completionHandler:nil];

If you're not relying on the RadarURLDelegate, you should implement

func application(_ app: UIApplication, open url: URL,
                     options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

or

func scene(_ scene: UIScene, 
           willConnectTo session: UISceneSession, 
           options connectionOptions: UIScene.ConnectionOptions)

React native setup

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"main";

  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  BOOL res = [super application:application didFinishLaunchingWithOptions:launchOptions];
  RadarInitializeOptions *radarInitializeOptions = [[RadarInitializeOptions alloc] init];
  radarInitializeOptions.autoHandleNotificationDeepLinks = YES;
  [Radar nativeSetup:radarInitializeOptions];
  return res;
}

Dogfood/ QA:

Using a custom build of waypoint using this dependency: https://expo.dev/accounts/radarlabs/projects/waypoint/builds/37c534bf-d646-4fbb-b412-17b3cd426cca
We create a on premise notification that deeplinks to the setting page.
This feature is currently only available in the staging env

trimmed.deep.link.screen.capture.mov

@KennyHuRadar KennyHuRadar changed the title iOS deep linking [WIP] iOS deep linking Oct 1, 2024
@KennyHuRadar KennyHuRadar marked this pull request as ready for review October 2, 2024 14:32
@KennyHuRadar KennyHuRadar changed the title [WIP] iOS deep linking iOS deep linking Oct 2, 2024
Copy link
Contributor

@lmeier lmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we tested this in Waypoint yet?

if (urlString) {
NSURL *url = [NSURL URLWithString:urlString];
if (url) {
if([[RadarDelegateHolder sharedInstance] didHandleURL:url]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linting

}
UIApplication *application = [UIApplication sharedApplication];
if ([application canOpenURL:url]) {
[application openURL:url options:@{} completionHandler:nil];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Call the original method (which is now swizzled)
[self swizzled_userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}

+ (void)handleURLFromNotification:(UNNotification *)notification {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to openURLFromNotification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants