Overview
Despia supports shared targets, allowing your application to receive data from any other application on iOS and Android through the native share sheet.
Setup
1. Enable Share Target
-
Go to Despia dashboard → Targets
-
Enable "Share into App"
-
Click "Publish Application" to rebuild
2. Variable Tracker Class
class VariableTracker {
constructor(variables, onReady) {
this.variables = variables;
this.onReady = onReady;
this.triggered = false;
this.processing = false;
// Create tracker element
this.tracker = document.createElement('div');
this.tracker.style.display = 'none';
document.body.appendChild(this.tracker);
// Setup observer with debounce
let timeout;
this.observer = new MutationObserver(() => {
clearTimeout(timeout);
timeout = setTimeout(() => this.check(), 100);
});
this.observer.observe(this.tracker, { attributes: true });
this.check();
this.interval = setInterval(() => this.check(), 1000);
}
check() {
if (this.processing || this.triggered) return;
this.processing = true;
try {
const values = {};
const allSet = this.variables.every(name => {
const val = window[name];
if (val === undefined || val === "n/a") return false;
values[name] = val;
return true;
});
if (allSet && !this.triggered) {
this.triggered = true;
this.cleanup();
this.onReady(values);
}
} catch (err) {
console.error("Error during check:", err);
}
this.processing = false;
}
cleanup() {
this.observer.disconnect();
clearInterval(this.interval);
this.tracker.remove();
}
}
3. Listen for Shared Data
new VariableTracker(
['sharedData'],
values => {
// Access data
console.log("Shared data:", values.sharedData); // Access the shared data
// Your code here
}
);
Data Types
Images
-
Received as data URL (e.g.,
data:image/png;base64,...
) -
Can be used directly as
src
attribute
Text/Links
-
Received as plain string
-
URLs can be validated with
new URL()
Important Notes
-
Initialize Variable Tracker on page load
-
The variable name is always
sharedData
-
Data is injected by Despia when app is opened via share
-
Only one share action is processed per app launch
For additional support or questions, please contact our support team at support@despia.com