'iOS AppDelegate.m: Handling openUrl RCTLinkingManager and Twitter - Duplicate declaration of method 'application:openURL:options:'

I need to add DeepLinking to my React Native app, and as mentioned in docs I need to add the method above @and.

// Add this above `@end`:
- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

I've added this method, but I also have similar one for Twitter login. Here's my AppDelegate.m:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
  return [[Twitter sharedInstance] application:app openURL:url options:options];
}

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


@end

I get an error: Duplicate declaration of method 'application:openURL:options:'

How can it be solved? I'm not an iOS developer, so it's hard to figure out, but I think both two methods should be somehow combined.



Solution 1:[1]

As the error suggests, you can not have multiple functions with the same signature. A simple solution here is merging your implementation into one, like this:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 congnd