Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

629
Visualizações
Handle URL scheme react-native and Swift

I would like to handle custom URL scheme in my react-native application. Thus I first added an eventListener in my JS code inside my root component like that :

componentDidMount() {
    Linking.addEventListener('url', this.handleOpenURL);
}

componentWillUnmount() {
    Linking.removeEventListener('url', this.handleOpenURL);
}

handleOpenURL = event => {
    console.log('event', event);
};

In my Xcode application, I added a custom URL scheme "com.myScheme".

My problem has appeared when I tried to add the function in my AppDelegate.swift to handle deep linking.

Here's my function :

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

It seems that return true is not enough to trigger my listener inside my application ...

I know there's an Objective-C method in the react-native documentation :

#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

But I would like to deal only with Swift for my project in order to improve my skills in this language. The problem is I can't find any example of this function implemented using Swift.

That's why I'm asking some help to implement this method and then trigger my event inside my RN application.

Thank you for your understanding :)

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Regarding your AppDelegate method, the swift version should be :

public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return RCTLinkingManager.application(app, open: url, options: options)
}
over 4 years ago · Santiago Trujillo Relatório

0

Ro22e0 's answer worked great for me. My app also supports universal bindings, so I also needed a quick equivalent for the following function provided in the React Native docs :

 - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler: (nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler { // Debug log something here return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; }

I'm not very comfortable with Swift, but I was finally able to get a working solution by trial and error:

 func application( _ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void ) -> Bool { return RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler) }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda