@capgo/capacitor-share-target 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorShareTarget.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +229 -0
- package/android/build.gradle +58 -0
- package/android/src/main/java/app/capgo/sharetarget/CapacitorShareTargetPlugin.java +203 -0
- package/dist/esm/definitions.d.ts +119 -0
- package/dist/esm/definitions.d.ts.map +1 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.d.ts.map +1 -0
- package/dist/esm/web.js +7 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +21 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +24 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorShareTargetPlugin/CapacitorShareTargetPlugin.swift +84 -0
- package/ios/Tests/CapacitorShareTargetPluginTests/CapacitorShareTargetPluginTests.swift +9 -0
- package/package.json +88 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapgoCapacitorShareTarget'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapgoCapacitorShareTarget",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapgoCapacitorShareTarget",
|
|
10
|
+
targets: ["CapacitorShareTargetPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.4.3")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "CapacitorShareTargetPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/CapacitorShareTargetPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "CapacitorShareTargetPluginTests",
|
|
25
|
+
dependencies: ["CapacitorShareTargetPlugin"],
|
|
26
|
+
path: "ios/Tests/CapacitorShareTargetPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# @capgo/capacitor-share-target
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to receive shared content from other apps.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @capgo/capacitor-share-target
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
### Android
|
|
15
|
+
|
|
16
|
+
Add the following to your `AndroidManifest.xml` inside the `<activity>` tag to allow your app to receive shared content:
|
|
17
|
+
|
|
18
|
+
```xml
|
|
19
|
+
<intent-filter>
|
|
20
|
+
<action android:name="android.intent.action.SEND" />
|
|
21
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
22
|
+
<data android:mimeType="text/*" />
|
|
23
|
+
</intent-filter>
|
|
24
|
+
<intent-filter>
|
|
25
|
+
<action android:name="android.intent.action.SEND" />
|
|
26
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
27
|
+
<data android:mimeType="image/*" />
|
|
28
|
+
</intent-filter>
|
|
29
|
+
<intent-filter>
|
|
30
|
+
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
|
31
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
32
|
+
<data android:mimeType="image/*" />
|
|
33
|
+
</intent-filter>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can customize the `mimeType` to match the types of content you want to receive (e.g., `text/*`, `image/*`, `video/*`, `*/*`).
|
|
37
|
+
|
|
38
|
+
### iOS
|
|
39
|
+
|
|
40
|
+
For iOS, you need to create a Share Extension to receive shared content. This requires additional setup:
|
|
41
|
+
|
|
42
|
+
1. In Xcode, go to File > New > Target
|
|
43
|
+
2. Select "Share Extension" and click Next
|
|
44
|
+
3. Name it (e.g., "ShareExtension") and click Finish
|
|
45
|
+
4. Configure the Share Extension to save data to a shared App Group
|
|
46
|
+
5. Update the `YOUR_APP_GROUP_ID` in the iOS plugin code
|
|
47
|
+
|
|
48
|
+
For detailed instructions, see the [iOS Share Extension documentation](https://developer.apple.com/documentation/uikit/uiactivityviewcontroller).
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
|
|
54
|
+
|
|
55
|
+
// Listen for shared content
|
|
56
|
+
CapacitorShareTarget.addListener('shareReceived', (event) => {
|
|
57
|
+
console.log('Title:', event.title);
|
|
58
|
+
console.log('Texts:', event.texts);
|
|
59
|
+
|
|
60
|
+
event.files?.forEach(file => {
|
|
61
|
+
console.log(`File: ${file.name}`);
|
|
62
|
+
console.log(`Type: ${file.mimeType}`);
|
|
63
|
+
console.log(`URI: ${file.uri}`);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
<docgen-index>
|
|
71
|
+
|
|
72
|
+
* [`addListener('shareReceived', ...)`](#addlistenersharereceived)
|
|
73
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
74
|
+
* [`getPluginVersion()`](#getpluginversion)
|
|
75
|
+
* [Interfaces](#interfaces)
|
|
76
|
+
|
|
77
|
+
</docgen-index>
|
|
78
|
+
|
|
79
|
+
<docgen-api>
|
|
80
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
81
|
+
|
|
82
|
+
### addListener('shareReceived', ...)
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
addListener(eventName: 'shareReceived', listenerFunc: (event: ShareReceivedEvent) => void) => Promise<PluginListenerHandle>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Listen for shareReceived event.
|
|
89
|
+
|
|
90
|
+
Registers a listener that will be called when content is shared to the application
|
|
91
|
+
from another app. The callback receives event data containing title, texts, and files.
|
|
92
|
+
|
|
93
|
+
| Param | Type | Description |
|
|
94
|
+
| ------------------ | ------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
95
|
+
| **`eventName`** | <code>'shareReceived'</code> | The event name. Must be 'shareReceived'. |
|
|
96
|
+
| **`listenerFunc`** | <code>(event: <a href="#sharereceivedevent">ShareReceivedEvent</a>) => void</code> | Callback function invoked when content is shared to the app. |
|
|
97
|
+
|
|
98
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
99
|
+
|
|
100
|
+
**Since:** 0.1.0
|
|
101
|
+
|
|
102
|
+
--------------------
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
### removeAllListeners()
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
removeAllListeners() => Promise<void>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Remove all listeners for this plugin.
|
|
112
|
+
|
|
113
|
+
**Since:** 0.1.0
|
|
114
|
+
|
|
115
|
+
--------------------
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### getPluginVersion()
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
getPluginVersion() => Promise<{ version: string; }>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Get the native Capacitor plugin version.
|
|
125
|
+
|
|
126
|
+
Returns the current version of the native plugin implementation.
|
|
127
|
+
|
|
128
|
+
**Returns:** <code>Promise<{ version: string; }></code>
|
|
129
|
+
|
|
130
|
+
**Since:** 0.1.0
|
|
131
|
+
|
|
132
|
+
--------------------
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### Interfaces
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
#### PluginListenerHandle
|
|
139
|
+
|
|
140
|
+
| Prop | Type |
|
|
141
|
+
| ------------ | ----------------------------------------- |
|
|
142
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
#### ShareReceivedEvent
|
|
146
|
+
|
|
147
|
+
Event data received when content is shared to the application.
|
|
148
|
+
|
|
149
|
+
| Prop | Type | Description | Since |
|
|
150
|
+
| ----------- | --------------------------- | -------------------------------------------------- | ----- |
|
|
151
|
+
| **`title`** | <code>string</code> | The title of the shared content. | 0.1.0 |
|
|
152
|
+
| **`texts`** | <code>string[]</code> | Array of text content shared to the application. | 0.1.0 |
|
|
153
|
+
| **`files`** | <code>SharedFile[]</code> | Array of files shared to the application. | 0.2.0 |
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
#### SharedFile
|
|
157
|
+
|
|
158
|
+
Represents a file shared to the application.
|
|
159
|
+
|
|
160
|
+
| Prop | Type | Description | Since |
|
|
161
|
+
| -------------- | ------------------- | ------------------------------------------------------------------------------------------------ | ----- |
|
|
162
|
+
| **`uri`** | <code>string</code> | The URI of the shared file. On Android/iOS this will be a file path or data URL. On web this will be a cached URL accessible via fetch. | 0.1.0 |
|
|
163
|
+
| **`name`** | <code>string</code> | The name of the shared file, with or without extension. | 0.1.0 |
|
|
164
|
+
| **`mimeType`** | <code>string</code> | The MIME type of the shared file. | 0.1.0 |
|
|
165
|
+
|
|
166
|
+
</docgen-api>
|
|
167
|
+
|
|
168
|
+
## Example
|
|
169
|
+
|
|
170
|
+
Here's a complete example of handling shared content in your app:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
|
|
174
|
+
import { Capacitor } from '@capacitor/core';
|
|
175
|
+
|
|
176
|
+
export class ShareService {
|
|
177
|
+
async initialize() {
|
|
178
|
+
// Only add listener on native platforms
|
|
179
|
+
if (Capacitor.isNativePlatform()) {
|
|
180
|
+
await CapacitorShareTarget.addListener('shareReceived', this.handleSharedContent);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private handleSharedContent(event: ShareReceivedEvent) {
|
|
185
|
+
console.log('Received shared content!');
|
|
186
|
+
|
|
187
|
+
// Handle shared text
|
|
188
|
+
if (event.texts.length > 0) {
|
|
189
|
+
console.log('Shared text:', event.texts[0]);
|
|
190
|
+
// Process the shared text (e.g., URL, note, etc.)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Handle shared files
|
|
194
|
+
if (event.files.length > 0) {
|
|
195
|
+
event.files.forEach(async (file) => {
|
|
196
|
+
console.log(`Processing file: ${file.name}`);
|
|
197
|
+
|
|
198
|
+
if (file.mimeType.startsWith('image/')) {
|
|
199
|
+
// Handle image files
|
|
200
|
+
await this.processImage(file.uri);
|
|
201
|
+
} else if (file.mimeType.startsWith('video/')) {
|
|
202
|
+
// Handle video files
|
|
203
|
+
await this.processVideo(file.uri);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private async processImage(uri: string) {
|
|
210
|
+
// Your image processing logic here
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private async processVideo(uri: string) {
|
|
214
|
+
// Your video processing logic here
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async cleanup() {
|
|
218
|
+
await CapacitorShareTarget.removeAllListeners();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Contributing
|
|
224
|
+
|
|
225
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "app.capgo.sharetarget"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
package app.capgo.sharetarget;
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.database.Cursor;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.provider.OpenableColumns;
|
|
7
|
+
import android.util.Log;
|
|
8
|
+
import android.webkit.MimeTypeMap;
|
|
9
|
+
import com.getcapacitor.JSArray;
|
|
10
|
+
import com.getcapacitor.JSObject;
|
|
11
|
+
import com.getcapacitor.Plugin;
|
|
12
|
+
import com.getcapacitor.PluginCall;
|
|
13
|
+
import com.getcapacitor.PluginMethod;
|
|
14
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
15
|
+
import java.io.File;
|
|
16
|
+
import java.io.FileOutputStream;
|
|
17
|
+
import java.io.InputStream;
|
|
18
|
+
import java.util.ArrayList;
|
|
19
|
+
|
|
20
|
+
@CapacitorPlugin(name = "CapacitorShareTarget")
|
|
21
|
+
public class CapacitorShareTargetPlugin extends Plugin {
|
|
22
|
+
|
|
23
|
+
private static final String TAG = "CapacitorShareTarget";
|
|
24
|
+
private static final String PLUGIN_VERSION = "7.0.0";
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public void load() {
|
|
28
|
+
super.load();
|
|
29
|
+
handleIntent(getActivity().getIntent());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Override
|
|
33
|
+
protected void handleOnNewIntent(Intent intent) {
|
|
34
|
+
super.handleOnNewIntent(intent);
|
|
35
|
+
handleIntent(intent);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private void handleIntent(Intent intent) {
|
|
39
|
+
if (intent == null) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
String action = intent.getAction();
|
|
44
|
+
String type = intent.getType();
|
|
45
|
+
|
|
46
|
+
if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
|
47
|
+
try {
|
|
48
|
+
JSObject shareData = new JSObject();
|
|
49
|
+
|
|
50
|
+
// Get title
|
|
51
|
+
String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
|
|
52
|
+
if (title == null) {
|
|
53
|
+
title = intent.getStringExtra(Intent.EXTRA_TITLE);
|
|
54
|
+
}
|
|
55
|
+
shareData.put("title", title != null ? title : "");
|
|
56
|
+
|
|
57
|
+
// Get texts
|
|
58
|
+
JSArray texts = new JSArray();
|
|
59
|
+
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
60
|
+
if (sharedText != null) {
|
|
61
|
+
texts.put(sharedText);
|
|
62
|
+
}
|
|
63
|
+
shareData.put("texts", texts);
|
|
64
|
+
|
|
65
|
+
// Get files
|
|
66
|
+
JSArray files = new JSArray();
|
|
67
|
+
if (Intent.ACTION_SEND.equals(action)) {
|
|
68
|
+
Uri fileUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
69
|
+
if (fileUri != null) {
|
|
70
|
+
JSObject fileData = getFileData(fileUri);
|
|
71
|
+
if (fileData != null) {
|
|
72
|
+
files.put(fileData);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
|
|
76
|
+
ArrayList<Uri> fileUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
|
77
|
+
if (fileUris != null) {
|
|
78
|
+
for (Uri fileUri : fileUris) {
|
|
79
|
+
JSObject fileData = getFileData(fileUri);
|
|
80
|
+
if (fileData != null) {
|
|
81
|
+
files.put(fileData);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
shareData.put("files", files);
|
|
87
|
+
|
|
88
|
+
// Notify listeners
|
|
89
|
+
notifyListeners("shareReceived", shareData);
|
|
90
|
+
Log.d(TAG, "Share received: " + shareData.toString());
|
|
91
|
+
} catch (Exception e) {
|
|
92
|
+
Log.e(TAG, "Error handling shared content", e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private JSObject getFileData(Uri uri) {
|
|
98
|
+
try {
|
|
99
|
+
JSObject fileData = new JSObject();
|
|
100
|
+
|
|
101
|
+
// Get file name
|
|
102
|
+
String fileName = getFileName(uri);
|
|
103
|
+
fileData.put("name", fileName != null ? fileName : "unknown");
|
|
104
|
+
|
|
105
|
+
// Get MIME type
|
|
106
|
+
String mimeType = getActivity().getContentResolver().getType(uri);
|
|
107
|
+
if (mimeType == null) {
|
|
108
|
+
mimeType = getMimeTypeFromFileName(fileName);
|
|
109
|
+
}
|
|
110
|
+
fileData.put("mimeType", mimeType != null ? mimeType : "application/octet-stream");
|
|
111
|
+
|
|
112
|
+
// Copy file to cache and get path
|
|
113
|
+
String filePath = copyFileToCache(uri, fileName);
|
|
114
|
+
fileData.put("uri", filePath != null ? filePath : uri.toString());
|
|
115
|
+
|
|
116
|
+
return fileData;
|
|
117
|
+
} catch (Exception e) {
|
|
118
|
+
Log.e(TAG, "Error getting file data for URI: " + uri, e);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private String getFileName(Uri uri) {
|
|
124
|
+
String fileName = null;
|
|
125
|
+
String scheme = uri.getScheme();
|
|
126
|
+
|
|
127
|
+
if ("content".equals(scheme)) {
|
|
128
|
+
try (Cursor cursor = getActivity().getContentResolver().query(uri, null, null, null, null)) {
|
|
129
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
130
|
+
int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
131
|
+
if (nameIndex != -1) {
|
|
132
|
+
fileName = cursor.getString(nameIndex);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} catch (Exception e) {
|
|
136
|
+
Log.e(TAG, "Error getting file name from cursor", e);
|
|
137
|
+
}
|
|
138
|
+
} else if ("file".equals(scheme)) {
|
|
139
|
+
fileName = new File(uri.getPath()).getName();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return fileName;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private String getMimeTypeFromFileName(String fileName) {
|
|
146
|
+
if (fileName == null) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
String extension = "";
|
|
151
|
+
int lastDot = fileName.lastIndexOf('.');
|
|
152
|
+
if (lastDot > 0) {
|
|
153
|
+
extension = fileName.substring(lastDot + 1);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private String copyFileToCache(Uri uri, String fileName) {
|
|
160
|
+
try {
|
|
161
|
+
File cacheDir = new File(getContext().getCacheDir(), "shared_files");
|
|
162
|
+
if (!cacheDir.exists()) {
|
|
163
|
+
cacheDir.mkdirs();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (fileName == null) {
|
|
167
|
+
fileName = "shared_file_" + System.currentTimeMillis();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
File outputFile = new File(cacheDir, fileName);
|
|
171
|
+
|
|
172
|
+
try (InputStream inputStream = getActivity().getContentResolver().openInputStream(uri);
|
|
173
|
+
FileOutputStream outputStream = new FileOutputStream(outputFile)) {
|
|
174
|
+
|
|
175
|
+
if (inputStream == null) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
byte[] buffer = new byte[4096];
|
|
180
|
+
int bytesRead;
|
|
181
|
+
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
182
|
+
outputStream.write(buffer, 0, bytesRead);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return outputFile.getAbsolutePath();
|
|
187
|
+
} catch (Exception e) {
|
|
188
|
+
Log.e(TAG, "Error copying file to cache", e);
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@PluginMethod
|
|
194
|
+
public void getPluginVersion(PluginCall call) {
|
|
195
|
+
try {
|
|
196
|
+
JSObject ret = new JSObject();
|
|
197
|
+
ret.put("version", PLUGIN_VERSION);
|
|
198
|
+
call.resolve(ret);
|
|
199
|
+
} catch (Exception e) {
|
|
200
|
+
call.reject("Could not get plugin version", e);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a file shared to the application.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.1.0
|
|
6
|
+
*/
|
|
7
|
+
export interface SharedFile {
|
|
8
|
+
/**
|
|
9
|
+
* The URI of the shared file. On Android/iOS this will be a file path or data URL.
|
|
10
|
+
* On web this will be a cached URL accessible via fetch.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
*/
|
|
14
|
+
uri: string;
|
|
15
|
+
/**
|
|
16
|
+
* The name of the shared file, with or without extension.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* The MIME type of the shared file.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.1.0
|
|
25
|
+
*/
|
|
26
|
+
mimeType: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Event data received when content is shared to the application.
|
|
30
|
+
*
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
*/
|
|
33
|
+
export interface ShareReceivedEvent {
|
|
34
|
+
/**
|
|
35
|
+
* The title of the shared content.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
*/
|
|
39
|
+
title: string;
|
|
40
|
+
/**
|
|
41
|
+
* Array of text content shared to the application.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.1.0
|
|
44
|
+
*/
|
|
45
|
+
texts: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Array of files shared to the application.
|
|
48
|
+
*
|
|
49
|
+
* @since 0.2.0
|
|
50
|
+
*/
|
|
51
|
+
files: SharedFile[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Capacitor Share Target Plugin interface.
|
|
55
|
+
*
|
|
56
|
+
* This plugin allows your application to receive content shared from other apps.
|
|
57
|
+
* Users can share text, URLs, and files to your app from other applications.
|
|
58
|
+
*
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
export interface CapacitorShareTargetPlugin {
|
|
62
|
+
/**
|
|
63
|
+
* Listen for shareReceived event.
|
|
64
|
+
*
|
|
65
|
+
* Registers a listener that will be called when content is shared to the application
|
|
66
|
+
* from another app. The callback receives event data containing title, texts, and files.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
* @param eventName The event name. Must be 'shareReceived'.
|
|
70
|
+
* @param listenerFunc Callback function invoked when content is shared to the app.
|
|
71
|
+
* @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle that can be used to remove the listener.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const listener = await CapacitorShareTarget.addListener('shareReceived', (event) => {
|
|
76
|
+
* console.log('Title:', event.title);
|
|
77
|
+
* console.log('Texts:', event.texts);
|
|
78
|
+
* event.files?.forEach(file => {
|
|
79
|
+
* console.log(`File: ${file.name} (${file.mimeType})`);
|
|
80
|
+
* });
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // To remove the listener:
|
|
84
|
+
* await listener.remove();
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
addListener(eventName: 'shareReceived', listenerFunc: (event: ShareReceivedEvent) => void): Promise<PluginListenerHandle>;
|
|
88
|
+
/**
|
|
89
|
+
* Remove all listeners for this plugin.
|
|
90
|
+
*
|
|
91
|
+
* @since 0.1.0
|
|
92
|
+
* @returns {Promise<void>} A promise that resolves when all listeners have been removed.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* await CapacitorShareTarget.removeAllListeners();
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
removeAllListeners(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Get the native Capacitor plugin version.
|
|
102
|
+
*
|
|
103
|
+
* Returns the current version of the native plugin implementation.
|
|
104
|
+
*
|
|
105
|
+
* @since 0.1.0
|
|
106
|
+
* @returns {Promise<{ version: string }>} A promise that resolves with an object containing the version string.
|
|
107
|
+
* @throws An error if something went wrong retrieving the version.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const { version } = await CapacitorShareTarget.getPluginVersion();
|
|
112
|
+
* console.log('Plugin version:', version);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
getPluginVersion(): Promise<{
|
|
116
|
+
version: string;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;OAIG;IACH,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,WAAW,CACT,SAAS,EAAE,eAAe,EAC1B,YAAY,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAChD,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEjC;;;;;;;;;;OAUG;IACH,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC;;;;;;;;;;;;;;OAcG;IACH,gBAAgB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAEhE,QAAA,MAAM,oBAAoB,4BAExB,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const CapacitorShareTarget = registerPlugin('CapacitorShareTarget', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.CapacitorShareTargetWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { CapacitorShareTarget };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,oBAAoB,GAAG,cAAc,CAA6B,sBAAsB,EAAE;IAC9F,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;CACxE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapacitorShareTargetPlugin } from './definitions';
|
|
3
|
+
export declare class CapacitorShareTargetWeb extends WebPlugin implements CapacitorShareTargetPlugin {
|
|
4
|
+
getPluginVersion(): Promise<{
|
|
5
|
+
version: string;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAEhE,qBAAa,uBAAwB,SAAQ,SAAU,YAAW,0BAA0B;IACpF,gBAAgB,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAGvD"}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpD,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const CapacitorShareTarget = core.registerPlugin('CapacitorShareTarget', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorShareTargetWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class CapacitorShareTargetWeb extends core.WebPlugin {
|
|
10
|
+
async getPluginVersion() {
|
|
11
|
+
return { version: 'web' };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
16
|
+
__proto__: null,
|
|
17
|
+
CapacitorShareTargetWeb: CapacitorShareTargetWeb
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
exports.CapacitorShareTarget = CapacitorShareTarget;
|
|
21
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorShareTarget = registerPlugin('CapacitorShareTarget', {\n web: () => import('./web').then((m) => new m.CapacitorShareTargetWeb()),\n});\nexport * from './definitions';\nexport { CapacitorShareTarget };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorShareTargetWeb extends WebPlugin {\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,oBAAoB,GAAGA,mBAAc,CAAC,sBAAsB,EAAE;AACpE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;AAC3E,CAAC;;ACFM,MAAM,uBAAuB,SAASC,cAAS,CAAC;AACvD,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var capacitorCapacitorShareTarget = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CapacitorShareTarget = core.registerPlugin('CapacitorShareTarget', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorShareTargetWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class CapacitorShareTargetWeb extends core.WebPlugin {
|
|
9
|
+
async getPluginVersion() {
|
|
10
|
+
return { version: 'web' };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
15
|
+
__proto__: null,
|
|
16
|
+
CapacitorShareTargetWeb: CapacitorShareTargetWeb
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
exports.CapacitorShareTarget = CapacitorShareTarget;
|
|
20
|
+
|
|
21
|
+
return exports;
|
|
22
|
+
|
|
23
|
+
})({}, core);
|
|
24
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorShareTarget = registerPlugin('CapacitorShareTarget', {\n web: () => import('./web').then((m) => new m.CapacitorShareTargetWeb()),\n});\nexport * from './definitions';\nexport { CapacitorShareTarget };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorShareTargetWeb extends WebPlugin {\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,oBAAoB,GAAGA,mBAAc,CAAC,sBAAsB,EAAE;IACpE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;IAC3E,CAAC;;ICFM,MAAM,uBAAuB,SAASC,cAAS,CAAC;IACvD,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(CapacitorShareTargetPlugin)
|
|
9
|
+
public class CapacitorShareTargetPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
private let PLUGIN_VERSION: String = "7.0.0"
|
|
11
|
+
public let identifier = "CapacitorShareTargetPlugin"
|
|
12
|
+
public let jsName = "CapacitorShareTarget"
|
|
13
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
14
|
+
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
override public func load() {
|
|
18
|
+
super.load()
|
|
19
|
+
|
|
20
|
+
// Check if the app was launched from a share extension
|
|
21
|
+
NotificationCenter.default.addObserver(
|
|
22
|
+
self,
|
|
23
|
+
selector: #selector(handleOpenURL(_:)),
|
|
24
|
+
name: .capacitorOpenURL,
|
|
25
|
+
object: nil
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
// Check for shared data on app launch
|
|
29
|
+
checkForSharedContent()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
deinit {
|
|
33
|
+
NotificationCenter.default.removeObserver(self)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc private func handleOpenURL(_ notification: Notification) {
|
|
37
|
+
guard let object = notification.object as? [String: Any],
|
|
38
|
+
let url = object["url"] as? URL else {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Handle share extension URL scheme
|
|
43
|
+
if url.scheme == "capacitor" && url.host == "share" {
|
|
44
|
+
checkForSharedContent()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private func checkForSharedContent() {
|
|
49
|
+
// Get shared content from UserDefaults (set by share extension)
|
|
50
|
+
if let userDefaults = UserDefaults(suiteName: "group.YOUR_APP_GROUP_ID") {
|
|
51
|
+
if let sharedData = userDefaults.dictionary(forKey: "SharedData") {
|
|
52
|
+
var shareEvent: [String: Any] = [:]
|
|
53
|
+
|
|
54
|
+
// Get title
|
|
55
|
+
shareEvent["title"] = sharedData["title"] as? String ?? ""
|
|
56
|
+
|
|
57
|
+
// Get texts
|
|
58
|
+
var texts: [String] = []
|
|
59
|
+
if let sharedTexts = sharedData["texts"] as? [String] {
|
|
60
|
+
texts = sharedTexts
|
|
61
|
+
}
|
|
62
|
+
shareEvent["texts"] = texts
|
|
63
|
+
|
|
64
|
+
// Get files
|
|
65
|
+
var files: [[String: Any]] = []
|
|
66
|
+
if let sharedFiles = sharedData["files"] as? [[String: Any]] {
|
|
67
|
+
files = sharedFiles
|
|
68
|
+
}
|
|
69
|
+
shareEvent["files"] = files
|
|
70
|
+
|
|
71
|
+
// Clear the shared data
|
|
72
|
+
userDefaults.removeObject(forKey: "SharedData")
|
|
73
|
+
userDefaults.synchronize()
|
|
74
|
+
|
|
75
|
+
// Notify listeners
|
|
76
|
+
notifyListeners("shareReceived", data: shareEvent)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
82
|
+
call.resolve(["version": self.PLUGIN_VERSION])
|
|
83
|
+
}
|
|
84
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/capacitor-share-target",
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "Receive shared content from other apps",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"CapgoCapacitorShareTarget.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "Cap-go <contact@capgo.app>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Cap-go/capacitor-share-target.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Cap-go/capacitor-share-target/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"share",
|
|
31
|
+
"share-target",
|
|
32
|
+
"sharing",
|
|
33
|
+
"native"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
37
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorShareTarget -destination generic/platform=iOS",
|
|
38
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
39
|
+
"verify:web": "npm run build",
|
|
40
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
41
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
42
|
+
"eslint": "eslint .",
|
|
43
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
44
|
+
"swiftlint": "node-swiftlint",
|
|
45
|
+
"docgen": "docgen --api CapacitorShareTargetPlugin --output-readme README.md --output-json dist/docs.json",
|
|
46
|
+
"build": "npm run clean && tsc && rollup -c rollup.config.mjs",
|
|
47
|
+
"clean": "rimraf ./dist",
|
|
48
|
+
"watch": "tsc --watch",
|
|
49
|
+
"prepublishOnly": "npm run build"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@capacitor/android": "^7.0.0",
|
|
53
|
+
"@capacitor/cli": "^7.0.0",
|
|
54
|
+
"@capacitor/core": "^7.0.0",
|
|
55
|
+
"@capacitor/docgen": "^0.3.0",
|
|
56
|
+
"@capacitor/ios": "^7.0.0",
|
|
57
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
58
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
59
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
60
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
61
|
+
"@types/node": "^22.13.1",
|
|
62
|
+
"eslint": "^8.57.0",
|
|
63
|
+
"eslint-plugin-import": "^2.31.0",
|
|
64
|
+
"husky": "^9.1.7",
|
|
65
|
+
"prettier": "^3.4.2",
|
|
66
|
+
"prettier-plugin-java": "^2.6.7",
|
|
67
|
+
"rimraf": "^6.0.1",
|
|
68
|
+
"rollup": "^4.34.6",
|
|
69
|
+
"swiftlint": "^2.0.0",
|
|
70
|
+
"typescript": "^5.7.3"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@capacitor/core": ">=7.0.0"
|
|
74
|
+
},
|
|
75
|
+
"eslintConfig": {
|
|
76
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
77
|
+
},
|
|
78
|
+
"prettier": "@ionic/prettier-config",
|
|
79
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
80
|
+
"capacitor": {
|
|
81
|
+
"ios": {
|
|
82
|
+
"src": "ios"
|
|
83
|
+
},
|
|
84
|
+
"android": {
|
|
85
|
+
"src": "android"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|