2

https://github.com/salesforce-marketingcloud/react-native-marketingcloudsdk

I would like to know which is the best way to implement url handling in React Native. There is documentation for both android and iOS (link at the bottom) on how to do that but when it comes to React Native there is no information anywhere. For Android there are pieces of code in Kotlin and for iOS happens the same but in Swift.

As you know, React Native uses Java/Objective-c out of the box and there is no clarification on how to implement those changes in those language. I think RN is wired differently and I do not know if is a matter of translating the code and putting it in the same place as the other documentation says. Some guidance would be much apreciated.

Thanks.

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/sdk-implementation/implementation-urlhandling.html

2 Answers 2

1

UrlHandling is passed into the MarketingCloudConfig. As such, you must implement it in native code. Examples of this can be seen in the Learning Applications: https://github.com/salesforce-marketingcloud/MarketingCloudSDK-Android/blob/master/app/src/main/java/com/salesforce/marketingcloud/learningapp/BaseLearningApplication.kt#L126

0

hope this will works,

.setNotificationCustomizationOptions(NotificationCustomizationOptions.create(R.drawable.ic_notification,
                new NotificationLaunchIntentProvider() {
                    @Override
                    public PendingIntent getNotificationPendingIntent(@NonNull Context context, @NonNull NotificationMessage notificationMessage) {
                        if(notificationMessage.url() != null && !notificationMessage.url().isEmpty()){
                            return PendingIntent.getActivity(context, new Random().nextInt(), new Intent(Intent.ACTION_VIEW, Uri.parse(notificationMessage.url())),
                                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE
                            );
                        }else {
                            return PendingIntent.getActivity(context, new Random().nextInt(),
                                    context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()),
                                    PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE
                            );
                        }
                    }
                }, null))
2
  • Code dumps make for bad answers. The explanation of how a solution works is as important as the solution itself.
    – Derek F
    Commented Nov 23, 2022 at 20:52
  • It's suggested to implement handling url native end by the RN library itself. Commented Nov 24, 2022 at 5:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .