Gathering detailed insights and metrics for orange-react-native-receive-sharing-intent
Gathering detailed insights and metrics for orange-react-native-receive-sharing-intent
Gathering detailed insights and metrics for orange-react-native-receive-sharing-intent
Gathering detailed insights and metrics for orange-react-native-receive-sharing-intent
A React Native plugin that enables React Native apps to receive sharing photos, videos, text, urls or any other file types from another app
npm install orange-react-native-receive-sharing-intent
Typescript
Module System
Node Version
NPM Version
JavaScript (34.42%)
Swift (24.77%)
Java (23.7%)
Ruby (7.87%)
Objective-C (6.83%)
Starlark (2.41%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
6 Stars
31 Commits
1 Watchers
3 Branches
1 Contributors
Updated on Jan 06, 2023
Latest Version
1.0.6
Package Id
orange-react-native-receive-sharing-intent@1.0.6
Unpacked Size
148.45 kB
Size
73.52 kB
File Count
26
NPM Version
6.14.11
Node Version
14.15.5
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
2
Note: This package is a fork from https://github.com/ajith-ab/react-native-receive-sharing-intent.
A React Native plugin that enables React Native apps to receive sharing photos, videos, text, urls or any other file types from another app.
Also, supports iOS Share extension and launching the host app automatically. Check the provided example for more info.
Android | Ios |
---|---|
![]() | ![]() |
1$ npm install react-native-receive-sharing-intent --save
1$ yarn add react-native-receive-sharing-intent
1$ cd ios && pod install
0.60.0
$ react-native link react-native-receive-sharing-intent
Note: Ios and Android on Debbuging time not working at sometimes while App is Closed
<Project_folder>/android/app/src/main/manifest.xml
1 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example"> 4 .... 5 <!--TODO Add this Line --> 6 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 7 8 <application .... > 9 <activity 10 .... 11 android:launchMode="singleTask"> <!--TODO IMPORTANT.set launchMode -> singleTask Recommended --> 12 13 ..... 14 <intent-filter> 15 <action android:name="android.intent.action.VIEW" /> 16 <category android:name="android.intent.category.DEFAULT" /> 17 <category android:name="android.intent.category.BROWSABLE" /> 18 <!--TODO: Add this filter, if you want support opening urls into your app--> 19 <data 20 android:scheme="https" 21 android:host="example.com" 22 android:pathPrefix="/invite"/> 23 </intent-filter> 24 25 <!--TODO: Add this filter, if you want to support sharing text into your app--> 26 <intent-filter> 27 <action android:name="android.intent.action.SEND" /> 28 <category android:name="android.intent.category.DEFAULT" /> 29 <data android:mimeType="text/*" /> 30 </intent-filter> 31 32 <!--TODO: Add this filter, if you want to support sharing images into your app--> 33 <intent-filter> 34 <action android:name="android.intent.action.SEND" /> 35 <category android:name="android.intent.category.DEFAULT" /> 36 <data android:mimeType="image/*" /> 37 </intent-filter> 38 39 <intent-filter> 40 <action android:name="android.intent.action.SEND_MULTIPLE" /> 41 <category android:name="android.intent.category.DEFAULT" /> 42 <data android:mimeType="image/*" /> 43 </intent-filter> 44 45 <!--TODO: Add this filter, if you want to support sharing videos into your app--> 46 <intent-filter> 47 <action android:name="android.intent.action.SEND" /> 48 <category android:name="android.intent.category.DEFAULT" /> 49 <data android:mimeType="video/*" /> 50 </intent-filter> 51 <intent-filter> 52 <action android:name="android.intent.action.SEND_MULTIPLE" /> 53 <category android:name="android.intent.category.DEFAULT" /> 54 <data android:mimeType="video/*" /> 55 </intent-filter> 56 57 <!--TODO: Add this filter, if you want to support sharing any type of files--> 58 <intent-filter> 59 <action android:name="android.intent.action.SEND" /> 60 <category android:name="android.intent.category.DEFAULT" /> 61 <data android:mimeType="*/*" /> 62 </intent-filter> 63 <intent-filter> 64 <action android:name="android.intent.action.SEND_MULTIPLE" /> 65 <category android:name="android.intent.category.DEFAULT" /> 66 <data android:mimeType="*/*" /> 67 </intent-filter> 68 69 ..... 70 71 </activity> 72 73 </application> 74 75</manifest>
<Project_folder>/android/app/src/main/java/com/YOUR_APP/MainActivity.java
:1 2// on top of your file 3import android.content.Intent; 4 5... 6 7public class MainActivity extends ReactActivity { 8 9... 10 11// on your MainActivity Class body 12@Override 13public void onNewIntent(Intent intent) { 14 super.onNewIntent(intent); 15 setIntent(intent); 16} 17 18... 19 20} 21
<project_folder>/ios/<project_name>/info.plist
1<plist version="1.0"> 2<dict> 3 4 ..... 5 6<key>CFBundleURLTypes</key> 7 <array> 8 <dict> 9 <key>CFBundleTypeRole</key> 10 <string>Editor</string> 11 <key>CFBundleURLSchemes</key> 12 <array> 13 <string>ShareMedia</string> 14 </array> 15 </dict> 16 <dict/> 17 </array> 18 19<key>NSPhotoLibraryUsageDescription</key> 20 <string> 21 To upload photos, please allow permission to access your photo library. 22 </string> 23 24 .... 25 26</dict> 27</plist>
<project_folder>/ios/<project_name>/AppDelegate.m
1.... 2 3#import <React/RCTLinkingManager.h> // Add this Line in Header of file 4 5.... 6@implementation AppDelegate 7 8... 9 10- (BOOL)application:(UIApplication *)application 11 openURL:(NSURL *)url 12 options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options 13{ 14 return [RCTLinkingManager application:application openURL:url options:options]; 15} 16 17@end 18
<project_folder>/ios/<your project name>/<your project name>.entitlements
1 2.... 3 <!--TODO: Add this tag, if you want support opening urls into your app--> 4 <key>com.apple.developer.associated-domains</key> 5 <array> 6 <string>applinks:example.com</string> 7 </array> 8.... 9
<project_folder>/ios/<Your Share Extension Name>/info.plist
1<plist version="1.0"> 2<dict> 3... 4 <key>NSExtension</key> 5 <dict> 6 <key>NSExtensionAttributes</key> 7 <dict> 8 <key>PHSupportedMediaTypes</key> 9 <array> 10 <!--TODO: Add this flag, if you want to support sharing video into your app--> 11 <string>Video</string> 12 <!--TODO: Add this flag, if you want to support sharing images into your app--> 13 <string>Image</string> 14 </array> 15 <key>NSExtensionActivationRule</key> 16 <dict> 17 <!--TODO: Add this flag, if you want to support sharing text into your app--> 18 <key>NSExtensionActivationSupportsText</key> 19 <true/> 20 <!--TODO: Add this tag, if you want to support sharing urls into your app--> 21 <key>NSExtensionActivationSupportsWebURLWithMaxCount</key> 22 <integer>1</integer> 23 <!--TODO: Add this flag, if you want to support sharing images into your app--> 24 <key>NSExtensionActivationSupportsImageWithMaxCount</key> 25 <integer>100</integer> 26 <!--TODO: Add this flag, if you want to support sharing video into your app--> 27 <key>NSExtensionActivationSupportsMovieWithMaxCount</key> 28 <integer>100</integer> 29 <!--TODO: Add this flag, if you want to support sharing other files into your app--> 30 <!--Change the integer to however many files you want to be able to share at a time--> 31 <key>NSExtensionActivationSupportsFileWithMaxCount</key> 32 <integer>100</integer> 33 </dict> 34 </dict> 35 <key>NSExtensionMainStoryboard</key> 36 <string>MainInterface</string> 37 <key>NSExtensionPointIdentifier</key> 38 <string>com.apple.share-services</string> 39 </dict> 40 41</dict> 42</plist> 43
<project_folder>/ios/<Your Share Extension Name>/ShareViewController.swift
hostAppBundleIdentifier
value to your main host app bundle identifier (example in my case: com.ajith.example
) in this ShareViewController.swift
1
2
3//
4// ShareViewController.swift
5// Example Share
6//
7// Created by Ajith A B on 30/05/20.
8//
9
10import UIKit
11import Social
12import MobileCoreServices
13import Photos
14
15class ShareViewController: SLComposeServiceViewController {
16 // TODO: IMPORTANT: This should be your host app bundle identifier
17 let hostAppBundleIdentifier = "com.ajith.example"
18 let sharedKey = "ShareKey"
19 var sharedMedia: [SharedMediaFile] = []
20 var sharedText: [String] = []
21 let imageContentType = kUTTypeImage as String
22 let videoContentType = kUTTypeMovie as String
23 let textContentType = kUTTypeText as String
24 let urlContentType = kUTTypeURL as String
25 let fileURLType = kUTTypeFileURL as String;
26
27 override func isContentValid() -> Bool {
28 return true
29 }
30
31 override func didSelectPost() {
32 // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
33 if let content = extensionContext!.inputItems[0] as? NSExtensionItem {
34 if let contents = content.attachments {
35 for (index, attachment) in (contents).enumerated() {
36 if attachment.hasItemConformingToTypeIdentifier(imageContentType) {
37 handleImages(content: content, attachment: attachment, index: index)
38 } else if attachment.hasItemConformingToTypeIdentifier(textContentType) {
39 handleText(content: content, attachment: attachment, index: index)
40 } else if attachment.hasItemConformingToTypeIdentifier(fileURLType) {
41 handleFiles(content: content, attachment: attachment, index: index)
42 } else if attachment.hasItemConformingToTypeIdentifier(urlContentType) {
43 handleUrl(content: content, attachment: attachment, index: index)
44 } else if attachment.hasItemConformingToTypeIdentifier(videoContentType) {
45 handleVideos(content: content, attachment: attachment, index: index)
46 }
47 }
48 }
49 }
50 }
51
52 override func configurationItems() -> [Any]! {
53 // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
54 return []
55 }
56
57 private func handleText (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
58 attachment.loadItem(forTypeIdentifier: textContentType, options: nil) { [weak self] data, error in
59
60 if error == nil, let item = data as? String, let this = self {
61
62 this.sharedText.append(item)
63
64 // If this is the last item, save imagesData in userDefaults and redirect to host app
65 if index == (content.attachments?.count)! - 1 {
66 let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
67 userDefaults?.set(this.sharedText, forKey: this.sharedKey)
68 userDefaults?.synchronize()
69 this.redirectToHostApp(type: .text)
70 }
71
72 } else {
73 self?.dismissWithError()
74 }
75 }
76 }
77
78 private func handleUrl (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
79 attachment.loadItem(forTypeIdentifier: urlContentType, options: nil) { [weak self] data, error in
80
81 if error == nil, let item = data as? URL, let this = self {
82
83 this.sharedText.append(item.absoluteString)
84
85 // If this is the last item, save imagesData in userDefaults and redirect to host app
86 if index == (content.attachments?.count)! - 1 {
87 let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
88 userDefaults?.set(this.sharedText, forKey: this.sharedKey)
89 userDefaults?.synchronize()
90 this.redirectToHostApp(type: .text)
91 }
92
93 } else {
94 self?.dismissWithError()
95 }
96 }
97 }
98
99 private func handleImages (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
100 attachment.loadItem(forTypeIdentifier: imageContentType, options: nil) { [weak self] data, error in
101
102 if error == nil, let url = data as? URL, let this = self {
103 // this.redirectToHostApp(type: .media)
104 // Always copy
105 let fileExtension = this.getExtension(from: url, type: .video)
106 let newName = UUID().uuidString
107 let newPath = FileManager.default
108 .containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
109 .appendingPathComponent("\(newName).\(fileExtension)")
110 let copied = this.copyFile(at: url, to: newPath)
111 if(copied) {
112 this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .image))
113 }
114
115 // If this is the last item, save imagesData in userDefaults and redirect to host app
116 if index == (content.attachments?.count)! - 1 {
117 let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
118 userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
119 userDefaults?.synchronize()
120 this.redirectToHostApp(type: .media)
121 }
122
123 } else {
124 self?.dismissWithError()
125 }
126 }
127 }
128
129 private func handleVideos (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
130 attachment.loadItem(forTypeIdentifier: videoContentType, options:nil) { [weak self] data, error in
131
132 if error == nil, let url = data as? URL, let this = self {
133
134 // Always copy
135 let fileExtension = this.getExtension(from: url, type: .video)
136 let newName = UUID().uuidString
137 let newPath = FileManager.default
138 .containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
139 .appendingPathComponent("\(newName).\(fileExtension)")
140 let copied = this.copyFile(at: url, to: newPath)
141 if(copied) {
142 guard let sharedFile = this.getSharedMediaFile(forVideo: newPath) else {
143 return
144 }
145 this.sharedMedia.append(sharedFile)
146 }
147
148 // If this is the last item, save imagesData in userDefaults and redirect to host app
149 if index == (content.attachments?.count)! - 1 {
150 let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
151 userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
152 userDefaults?.synchronize()
153 this.redirectToHostApp(type: .media)
154 }
155
156 } else {
157 self?.dismissWithError()
158 }
159 }
160 }
161
162 private func handleFiles (content: NSExtensionItem, attachment: NSItemProvider, index: Int) {
163 attachment.loadItem(forTypeIdentifier: fileURLType, options: nil) { [weak self] data, error in
164
165 if error == nil, let url = data as? URL, let this = self {
166
167 // Always copy
168 let newName = this.getFileName(from :url)
169 let newPath = FileManager.default
170 .containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
171 .appendingPathComponent("\(newName)")
172 let copied = this.copyFile(at: url, to: newPath)
173 if (copied) {
174 this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .file))
175 }
176
177 if index == (content.attachments?.count)! - 1 {
178 let userDefaults = UserDefaults(suiteName: "group.\(this.hostAppBundleIdentifier)")
179 userDefaults?.set(this.toData(data: this.sharedMedia), forKey: this.sharedKey)
180 userDefaults?.synchronize()
181 this.redirectToHostApp(type: .file)
182 }
183
184 } else {
185 self?.dismissWithError()
186 }
187 }
188 }
189
190 private func dismissWithError() {
191 print("[ERROR] Error loading data!")
192 let alert = UIAlertController(title: "Error", message: "Error loading data", preferredStyle: .alert)
193
194 let action = UIAlertAction(title: "Error", style: .cancel) { _ in
195 self.dismiss(animated: true, completion: nil)
196 }
197
198 alert.addAction(action)
199 present(alert, animated: true, completion: nil)
200 extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
201 }
202
203 private func redirectToHostApp(type: RedirectType) {
204 let url = URL(string: "ShareMedia://dataUrl=\(sharedKey)#\(type)")
205 var responder = self as UIResponder?
206 let selectorOpenURL = sel_registerName("openURL:")
207
208 while (responder != nil) {
209 if (responder?.responds(to: selectorOpenURL))! {
210 let _ = responder?.perform(selectorOpenURL, with: url)
211 }
212 responder = responder!.next
213 }
214 extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
215 }
216
217 enum RedirectType {
218 case media
219 case text
220 case file
221 }
222
223 func getExtension(from url: URL, type: SharedMediaType) -> String {
224 let parts = url.lastPathComponent.components(separatedBy: ".")
225 var ex: String? = nil
226 if (parts.count > 1) {
227 ex = parts.last
228 }
229
230 if (ex == nil) {
231 switch type {
232 case .image:
233 ex = "PNG"
234 case .video:
235 ex = "MP4"
236 case .file:
237 ex = "TXT"
238 }
239 }
240 return ex ?? "Unknown"
241 }
242
243 func getFileName(from url: URL) -> String {
244 var name = url.lastPathComponent
245
246 if (name == "") {
247 name = UUID().uuidString + "." + getExtension(from: url, type: .file)
248 }
249
250 return name
251 }
252
253 func copyFile(at srcURL: URL, to dstURL: URL) -> Bool {
254 do {
255 if FileManager.default.fileExists(atPath: dstURL.path) {
256 try FileManager.default.removeItem(at: dstURL)
257 }
258 try FileManager.default.copyItem(at: srcURL, to: dstURL)
259 } catch (let error) {
260 print("Cannot copy item at \(srcURL) to \(dstURL): \(error)")
261 return false
262 }
263 return true
264 }
265
266 private func getSharedMediaFile(forVideo: URL) -> SharedMediaFile? {
267 let asset = AVAsset(url: forVideo)
268 let duration = (CMTimeGetSeconds(asset.duration) * 1000).rounded()
269 let thumbnailPath = getThumbnailPath(for: forVideo)
270
271 if FileManager.default.fileExists(atPath: thumbnailPath.path) {
272 return SharedMediaFile(path: forVideo.absoluteString, thumbnail: thumbnailPath.absoluteString, duration: duration, type: .video)
273 }
274
275 var saved = false
276 let assetImgGenerate = AVAssetImageGenerator(asset: asset)
277 assetImgGenerate.appliesPreferredTrackTransform = true
278 // let scale = UIScreen.main.scale
279 assetImgGenerate.maximumSize = CGSize(width: 360, height: 360)
280 do {
281 let img = try assetImgGenerate.copyCGImage(at: CMTimeMakeWithSeconds(600, preferredTimescale: Int32(1.0)), actualTime: nil)
282 try UIImage.pngData(UIImage(cgImage: img))()?.write(to: thumbnailPath)
283 saved = true
284 } catch {
285 saved = false
286 }
287
288 return saved ? SharedMediaFile(path: forVideo.absoluteString, thumbnail: thumbnailPath.absoluteString, duration: duration, type: .video) : nil
289
290 }
291
292 private func getThumbnailPath(for url: URL) -> URL {
293 let fileName = Data(url.lastPathComponent.utf8).base64EncodedString().replacingOccurrences(of: "==", with: "")
294 let path = FileManager.default
295 .containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
296 .appendingPathComponent("\(fileName).jpg")
297 return path
298 }
299
300 class SharedMediaFile: Codable {
301 var path: String; // can be image, video or url path. It can also be text content
302 var thumbnail: String?; // video thumbnail
303 var duration: Double?; // video duration in milliseconds
304 var type: SharedMediaType;
305
306
307 init(path: String, thumbnail: String?, duration: Double?, type: SharedMediaType) {
308 self.path = path
309 self.thumbnail = thumbnail
310 self.duration = duration
311 self.type = type
312 }
313
314 // Debug method to print out SharedMediaFile details in the console
315 func toString() {
316 print("[SharedMediaFile] \n\tpath: \(self.path)\n\tthumbnail: \(self.thumbnail)\n\tduration: \(self.duration)\n\ttype: \(self.type)")
317 }
318 }
319
320 enum SharedMediaType: Int, Codable {
321 case image
322 case video
323 case file
324 }
325
326 func toData(data: [SharedMediaFile]) -> Data {
327 let encodedData = try? JSONEncoder().encode(data)
328 return encodedData!
329 }
330}
331
332extension Array {
333 subscript (safe index: UInt) -> Element? {
334 return Int(index) < count ? self[Int(index)] : nil
335 }
336}
337
338
339
340
Go to the Capabilities tab and switch on the App Groups switch for both targets. Add a new group and name it group.YOUR_HOST_APP_BUNDLE_IDENTIFIER in my case group.com.ajith.example
App group name must be start with group.
Error: App does not build after adding Share Extension?
Fix: Check Build Settings of your share extension and remove everything that tries to import Cocoapods from your main project. i.e. remove everything under Linking/Other Linker Flags
You might need to disable bitcode for the extension target
1import ReceiveSharingIntent from 'react-native-receive-sharing-intent'; 2 3 4 // To get All Recived Urls 5 ReceiveSharingIntent.getReceivedFiles(files => { 6 // files returns as JSON Array example 7 //[{ filePath: null, text: null, weblink: null, mimeType: null, contentUri: null, fileName: null, extension: null }] 8 }, 9 (error) =>{ 10 console.log(error); 11 }); 12 13 14 // To clear Intents 15 ReceiveSharingIntent.clearReceivedFiles(); 16
MIT
No vulnerabilities found.
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
57 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More