react-native-share-menu icon indicating copy to clipboard operation
react-native-share-menu copied to clipboard

duplicate declaration RCTLinking Manager and ShareMenuManager

Open Epiczzor opened this issue 5 years ago • 4 comments

I get an error saying 'duplicate declaration of method application'. I had already added a method with the name for deep linking for RCTLinkingManager. what can I do to solve this issue such that I can use both. Sorry if this is a noob question I have zero experience in Swift

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

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

Epiczzor avatar Feb 03 '21 17:02 Epiczzor

Same issue

interstates21 avatar Feb 16 '21 22:02 interstates21

For my case, I solved it like this. Just merged the two application methods and added a check for the url argument. However, I only needed to look out for the prefix of the openURL argument. You might want to change the urlString check so that it recognises your custom deep links.

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  
  //  Check if the passed url is a <YOUR_URL_SCHEME_NAME>://- or a Spotify-url
  NSString *urlString = url.absoluteString;
  
  
  //  If it contains <YOUR_URL_SCHEME_NAME>:// handle it with the ShareMenuManager
  if ([urlString hasPrefix:@"<YOUR_URL_SCHEME_NAME>://"]) {
    NSLog(@"Entered with the following string: %@s", urlString);
    return [ShareMenuManager application:application openURL:url options:options];
  }
  
  // Else, go into react-native-spotify-remote
  return [[RNSpotifyRemoteAuth sharedInstance] application:application openURL:url options:options];
}

Hope this helps although it's not the entire solution to your problem.

yannikw23 avatar Feb 19 '21 12:02 yannikw23

doesn't the share extension use the same url scheme?

Can anyone provide a snippet merging RCTLinkingManager and ShareMenuManager in the openURL method?

I'd bet >90% of react-native-share-menu already use react-navigation with deep links, so are confronted with this issue. This is more of a request for documentation than an issue per se

ice-cap0 avatar Jan 04 '23 13:01 ice-cap0

@shawarmaz not sure if you got this yet or not, but here's the solution I used...

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  
  // check url string
  NSString *urlString = url.absoluteString;
  
  // if url contains ShareExtension prefix, handle with ShareMenuManager
  if ([urlString hasPrefix:@"<YOUR_URL_SCHEME_NAME>://"]) {
    NSLog(@"Entered with the following string: %@s", urlString);
    return [ShareMenuManager application:application openURL:url options:options];
  }
  
  // else use React Native Linking
  return [RCTLinkingManager application:application openURL:url options:options];
}

DanC5 avatar Jan 15 '23 15:01 DanC5