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

Deep link invocation when app is in quit state on iOS is not working #145

Closed
claire-euni opened this issue Mar 25, 2022 · 7 comments
Closed

Comments

@claire-euni
Copy link

claire-euni commented Mar 25, 2022

Hi guys,
I installed Braze React Native SDK and added Integrating push notifications in React Native according to the guide . I have tested push notifications on dashboard, deep link invocation works very well when app is active on both foreground and background, except for the situation when app is quit state (killed). I was able to receive push notification when app is killed, however when I clicked push, it only opens and does not navigate to a specific deep link destination.

Could anyone tell what I have done wrong in code?

  • version info
    "react-native-appboy-sdk": "^1.33.1"
    "react-native": "0.66.3"
// AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

... 
 if (@available(iOS 10.0, *)) {
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
      if (settings.authorizationStatus != UNAuthorizationStatusNotDetermined) {
        // authorization has already been requested, need to follow usual steps
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
          [[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted];
        }];
        center.delegate = self;
        [center setNotificationCategories:[ABKPushUtils getAppboyUNNotificationCategorySet]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
      }
    }];
  } else {
    UIApplication *sharedApplication = [UIApplication sharedApplication];
    UIUserNotificationSettings *notificationSettings = [sharedApplication currentUserNotificationSettings];
    if (notificationSettings.types) {
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:[ABKPushUtils getAppboyUIUserNotificationCategorySet]];
      [sharedApplication registerUserNotificationSettings:settings];
      [sharedApplication registerForRemoteNotifications];
    }
  }
...

 // Register for user notifications
  if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
    if (@available(iOS 12.0, *)) {
      options = options | UNAuthorizationOptionProvisional;
    }
    [center requestAuthorizationWithOptions:(options)
                          completionHandler:^(BOOL granted, NSError *_Nullable error) {
                            NSLog(@"Permission granted.");
                            [[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted];
                          }];
    [center setNotificationCategories:[ABKPushUtils getAppboyUNNotificationCategorySet]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
  } else {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  }

  [[AppboyReactUtils sharedInstance] populateInitialUrlFromLaunchOptions:launchOptions];

    // In-App Messaging
  [Appboy sharedInstance].inAppMessageController.delegate = self;

  return YES;
}
// App.js

		ReactAppboy.getInitialURL(link => {
			return link;
		});
@Bucimis
Copy link
Collaborator

Bucimis commented Mar 25, 2022

@claire-euni

  1. Did you implement the rest of the User Notification Framework methods in your AppDelegate, e.g. https://github.com/Appboy/appboy-react-sdk/blob/38c2e256eaeedadf27b046e053b748bd61352456/AppboyProject/ios/AppboyProject/AppDelegate.m#L68
  2. Are you passing in launchOptions to startWithApiKey, e.g. https://github.com/Appboy/appboy-react-sdk/blob/38c2e256eaeedadf27b046e053b748bd61352456/AppboyProject/ios/AppboyProject/AppDelegate.m#L30
  3. If you add Linking.getInitialUrl to your App.js, does that capture the deep link? https://github.com/Appboy/appboy-react-sdk/blob/38c2e256eaeedadf27b046e053b748bd61352456/AppboyProject/AppboyProject.js#L71
  4. Do you see this log populating with the expected URI (required for ReactAppboy.getInitialURL to work)? https://github.com/Appboy/appboy-react-sdk/blob/3d68180e912e10c60c92658d201628e7c1ee7872/iOS/AppboyReactBridge/AppboyReactBridge/AppboyReactUtils.m#L26

@claire-euni
Copy link
Author

claire-euni commented Mar 30, 2022

@Bucimis
I already have implemented 1,2,3 you mentioned above and I checked 4 in AppboyReactUtils.m . I could managed to receive the deep link I've had sent, and it's working well from time to time (don't know why) but mostly just opened app and crashed. FYI, I'm sending ios push with CONTENT-AVAILABLE FLAG on, but without it the result is still the same.
(reference : https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app)

// App.js

const linking = {
	prefixes: [
		'{myApp}://',
	],

	async getInitialURL() {
		ReactAppboy.getInitialURL(brazeLink => {
                   if(brazeLink) {
                   // ** log check : received the braze deep link** 
                 };
		});

          return '{myApp}://splash';
      },

	subscribe(listener) {
		const onReceiveURL = ({ url }) => listener(url);
		Linking.addEventListener('url', onReceiveURL);

                return () => {
			Linking.removeEventListener('url', onReceiveURL);
		};
},
....
// config settings
};

const App = () => {
	const handleOpenUrl = event => {
		   // **log check :  received the braze deep link = event.url** 
	};

        useEffect(() => {
		Linking.addEventListener('url', handleOpenUrl);
		Linking.getInitialURL()
			.then(url => {
				if (url) {
					handleOpenUrl({ url });
				}
			})
			.catch(err => console.error('Error getting initial URL', err));

		const listener = DeviceEventEmitter.addListener(
			'inAppMessageReceived',
			function (event) {
				const inAppMessage = new ReactAppboy.BrazeInAppMessage(
					event.inAppMessage,
				);
				ReactAppboy.logInAppMessageClicked(inAppMessage);
				ReactAppboy.logInAppMessageImpression(inAppMessage);
				ReactAppboy.logInAppMessageButtonClicked(inAppMessage, 0);
			},
		);

		return () => {
			listener?.remove();
			Linking.removeEventListener('url', handleOpenUrl);
		};
	}, []);
};

@Bucimis
Copy link
Collaborator

Bucimis commented Mar 30, 2022

@claire-euni if you print "hello world" logs from your didFinishLaunching and UserNotificationFramework delegates in your native iOS code, do you at least see those? Once you see those, you should be able to trace how the deep link flows through the system and where it stops working/gets dropped.

@claire-euni
Copy link
Author

@Bucimis I have sorted it out! The problem was that I did not set the correct function to get initial link using Appboy so it did not return the deep link. Now deep linking is working very well on quit state. I really appreciate your help! :)

@Meet-JS
Copy link

Meet-JS commented Feb 15, 2023

@claire-euni Would you mind sharing more details please? May be code block of the correct function. Would really appreciate it. Thanks.

@agatharejina
Copy link

@claire-euni hi! mind sharing the details on your solutin? my case is, it seems that the get initial url doesn't seem to return the deep link too. Thanks before

@Meet-JS
Copy link

Meet-JS commented Mar 6, 2023

For me this works:

// Handles deep links when an iOS app is launched from hard close via push click.
 Braze.getInitialURL((url) => {
      // logic
    });

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

No branches or pull requests

4 participants