Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ankipro/react-native-file-open

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ankipro/react-native-file-open

React Native file opening listener for iOS

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
128
increased by24.27%
Maintainers
1
Weekly downloads
 
Created
Source

@ankipro/react-native-file-open

Library empowers to seamlessly detect and handle external file openings on iOS. You can allowing your app to respond when users attempt to open files from other apps or external sources.

Installation

yarn add @ankipro/react-native-file-open
npx pod-install

Sorry but, you need to modify your ios/AppDelegate.m. At the top of the file, import the RNFileOpen right before '@implementation AppDelegate':

@import RNFileOpen;

Within your existing didFinishLaunchingWithOptions method, add the following method:

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

  // Add me --- \/
  NSURL *_Nullable launchURL = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
  if (launchURL) {
    [[FileOpeningModule sharedInstance] markFileOpened:launchURL];
  }
  // Add me --- /\

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

At the end of the file add the following:

// Add me --- \/
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
  [[FileOpeningModule sharedInstance] markFileOpened:url];
  return YES;
}
// Add me --- /\

@end

If you want the app to appear in suggestions when you open certain files on your device, you need to add the desired extensions in the project info.

For example adding .zip extension looks like:

adding_zip_extension_in_project_settings

Basic usage

import FileOpening from '@ankipro/react-native-file-open';

// ...

 useEffect(() => {
    const onFileOpened = (uri: string) => {
      console.log('Opened file: ', uri);
    };

    FileOpening.getOpenedFileURL().then(onFileOpened).catch(() => {});

    const subscription = FileOpening.addListener((data) => {
      onFileOpened(data.url);
    });

    return () => {
      subscription.remove();
    };
  }, []);

For more information see example.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

Keywords

FAQs

Package last updated on 11 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc