Use the iOS clipboard safely

Copy a public reference and read the clipboard only after an explicit action, without placing the private note on it.
iOS

What you will build

Let the person copy or paste deliberately and explain the actual result without treating clipboard access as private storage.
Keep private note text separate from the public reference being copied
Decode copy and read completions, including empty or unavailable content
Check native and browser behaviour without treating write acceptance as readback proof
A clipboard is shared with other applications. That makes copying a public work reference a different operation from copying the entire screen, which may contain a private note. The safest boundary is to make the copy action receive only the field that is meant to leave the app.
We will build a screen where the user enters both values. One explicit action copies the reference; another explicitly reads clipboard text. The private note remains local UI memory and never becomes an argument to the clipboard effect. There are no startup reads, automatic polling or simulated clipboard providers.
Start from a new project (optional)

Create the project and add the target

Complete iOS setup first. Clipboard text is available through the normal shell, so this example does not add a capability declaration.
cargo install cargo-fission
fission init ios-use-the-ios-clipboard-safely
cd ios-use-the-ios-clipboard-safely
fission add-target ios --project-dir .
cargo add serde_yaml
Keep the generated src/main.rs and replace src/lib.rs below. The normal native and Web launchers must install the same shared app as the preview, not leave the generated counter running.

Run the finished example

fission run --target ios --project-dir .

1. Make the copied field an explicit input

The reference belongs to shared hand-off state. The private note belongs to this screen's retained local state; other screens and the clipboard service do not need access to it. That separation prevents accidental inclusion in the copy request without requiring the service to filter a whole work-order object.
{"id":"fission-tabs-1","tabs":[{"index":0,"label":"src/app.rs","value":"src-app-rs"},{"index":1,"label":"src/app/state.rs","value":"src-app-state-rs"},{"index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"},{"index":3,"label":"src/i18n.rs","value":"src-i18n-rs"},{"index":4,"label":"src/lib.rs","value":"src-lib-rs"},{"index":5,"label":"preview/lib.rs","value":"preview-lib-rs"},{"index":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"},{"index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}]}
{"id":"fission-tabs-1","index":0,"label":"src/app.rs","value":"src-app-rs"}
pub mod screen;
pub mod state;

pub use screen::ClipboardScreen;
pub use state::ClipboardState;
{"id":"fission-tabs-1","index":1,"label":"src/app/state.rs","value":"src-app-state-rs"}
use fission::prelude::*;

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum ClipboardStatus {
    #[default]
    Idle,
    Writing,
    Reading,
    WriteAccepted,
    ReadText,
    Empty,
    Failed,
    InvalidResult,
}

impl ClipboardStatus {
    pub fn pending(&self) -> bool {
        matches!(self, Self::Writing | Self::Reading)
    }

    pub fn message_key(&self) -> &'static str {
        match self {
            Self::Idle => "clipboard.idle",
            Self::Writing => "clipboard.writing",
            Self::Reading => "clipboard.reading",
            Self::WriteAccepted => "clipboard.write_accepted",
            Self::ReadText => "clipboard.read_text",
            Self::Empty => "clipboard.empty",
            Self::Failed => "clipboard.failed",
            Self::InvalidResult => "clipboard.invalid",
        }
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClipboardState {
    pub public_reference: String,
    pub last_pasted: Option<String>,
    pub status: ClipboardStatus,
    pub locale: Locale,
}

impl Default for ClipboardState {
    fn default() -> Self {
        Self {
            public_reference: String::new(),
            last_pasted: None,
            status: ClipboardStatus::Idle,
            locale: Locale::from("en-US"),
        }
    }
}

impl GlobalState for ClipboardState {}

pub fn copy_reference(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
    if state.status.pending() || state.public_reference.trim().is_empty() {
        return;
    }
    state.status = ClipboardStatus::Writing;
    let ok = cx
        .effects
        .bind(CopyAccepted, reduce_with!(on_copy_accepted));
    let err = cx.effects.bind(CopyFailed, reduce_with!(on_copy_failed));
    cx.effects
        .clipboard()
        .write_text(ClipboardWriteTextRequest {
            text: state.public_reference.clone(),
        })
        .on_ok(ok)
        .on_err(err);
}

pub fn paste_reference(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
    if state.status.pending() {
        return;
    }
    state.status = ClipboardStatus::Reading;
    let ok = cx
        .effects
        .bind(PasteReceived, reduce_with!(on_paste_received));
    let err = cx.effects.bind(PasteFailed, reduce_with!(on_paste_failed));
    cx.effects.clipboard().read_text().on_ok(ok).on_err(err);
}

#[fission_reducer(CopyAccepted)]
fn on_copy_accepted(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
    state.status = if cx.input.capability_ok(WRITE_CLIPBOARD_TEXT).is_some() {
        ClipboardStatus::WriteAccepted
    } else {
        ClipboardStatus::InvalidResult
    };
}

#[fission_reducer(CopyFailed)]
fn on_copy_failed(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
    state.status = if cx.input.capability_error(WRITE_CLIPBOARD_TEXT).is_some() {
        ClipboardStatus::Failed
    } else {
        ClipboardStatus::InvalidResult
    };
}

#[fission_reducer(PasteReceived)]
fn on_paste_received(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
    let Some(result) = cx.input.capability_ok(READ_CLIPBOARD_TEXT) else {
        state.status = ClipboardStatus::InvalidResult;
        return;
    };
    state.last_pasted = result.text.filter(|text| !text.is_empty());
    state.status = if state.last_pasted.is_some() {
        ClipboardStatus::ReadText
    } else {
        ClipboardStatus::Empty
    };
}

#[fission_reducer(PasteFailed)]
fn on_paste_failed(state: &mut ClipboardState, cx: &mut ReducerContext<ClipboardState>) {
    state.status = if cx.input.capability_error(READ_CLIPBOARD_TEXT).is_some() {
        ClipboardStatus::Failed
    } else {
        ClipboardStatus::InvalidResult
    };
}
{"id":"fission-tabs-1","index":2,"label":"src/app/screen.rs","value":"src-app-screen-rs"}
use super::state::{copy_reference, paste_reference, ClipboardState};
use fission::prelude::*;

fission_component! {
    pub ClipboardScreen<ClipboardState> {
        state {
            private_note: String = String::new(),
        }
    }
    view(screen, state, cx) {
        let tokens = &cx.view.env().theme.tokens;
        let pending = state.status.pending();
    } => SafeArea(
        child: Scroll(
            child: Container(
                Column(gap: tokens.spacing.m, children: [
                    Text(cx.tr("clipboard.title"))
                        .size(tokens.typography.heading2_size),
                    Text(cx.tr("clipboard.explanation"))
                        .color(tokens.colors.text_secondary),
                    Row(gap: tokens.spacing.s, children: [
                        Button(
                            child: Text(cx.tr("language.english")),
                            key: "english",
                            on_press: reduce { state.locale = Locale::from("en-US"); },
                        ),
                        Button(
                            child: Text(cx.tr("language.spanish")),
                            key: "spanish",
                            on_press: reduce { state.locale = Locale::from("es-ES"); },
                        ),
                    ]),
                    FormControl(
                        label: Some(cx.tr("clipboard.reference")),
                        required: true,
                        child: TextInput(
                            value: state.public_reference.clone(),
                            bind(on_input): to(state.public_reference),
                            semantics_identifier: Some("clipboard.reference".into()),
                        ),
                    ),
                    TextInput(
                        value: screen.private_note.clone(),
                        bind(on_input): to(screen.private_note),
                        label: Some(TextContent::Key("clipboard.private_note".into())),
                        helper_text: Some(TextContent::Key("clipboard.private_help".into())),
                        multiline: true,
                        semantics_identifier: Some("clipboard.private-note".into()),
                    ),
                    Button(
                        child: Text(cx.tr("clipboard.copy")),
                        key: "copy-reference",
                        disabled: pending || state.public_reference.trim().is_empty(),
                        on_press: reduce { copy_reference(state, cx); },
                    ),
                    Button(
                        child: Text(cx.tr("clipboard.paste")),
                        key: "paste-reference",
                        disabled: pending,
                        on_press: reduce { paste_reference(state, cx); },
                    ),
                    if pending {
                        Spinner(
                            motion: Some(SpinnerMotion::Default),
                            label: Some(cx.tr(state.status.message_key())),
                        )
                    },
                    Text(cx.tr(state.status.message_key())),
                    if let Some(text) = &state.last_pasted {
                        Column(gap: tokens.spacing.s, children: [
                            Text(cx.tr("clipboard.last_pasted")),
                            TextInput(
                                value: text.clone(),
                                read_only: true,
                                multiline: true,
                                label: Some(TextContent::Key("clipboard.pasted_text".into())),
                            ),
                        ])
                    },
                ]),
            )
            .padding_all(tokens.spacing.l)
            .bg(tokens.colors.surface),
        ),
    )
}
{"id":"fission-tabs-1","index":3,"label":"src/i18n.rs","value":"src-i18n-rs"}
use fission::i18n::{Locale, TranslationBundle};
use fission::prelude::*;
use std::collections::HashMap;

pub fn create_env() -> Env {
    let mut env = Env::default();
    env.locale = Locale::from("en-US");
    for (locale, source) in [
        ("en-US", include_str!("../i18n/en-US.yaml")),
        ("es-ES", include_str!("../i18n/es-ES.yaml")),
    ] {
        let messages: HashMap<String, String> =
            serde_yaml::from_str(source).expect("valid clipboard translations");
        env.i18n.add_bundle(TranslationBundle {
            locale: Locale::from(locale),
            messages,
        });
    }
    env
}

pub fn sync_env(state: &crate::app::ClipboardState, env: &mut Env) {
    env.locale = state.locale.clone();
}
{"id":"fission-tabs-1","index":4,"label":"src/lib.rs","value":"src-lib-rs"}
pub mod app;
mod i18n;

use app::{ClipboardScreen, ClipboardState};
use fission::prelude::*;

#[cfg(not(any(target_arch = "wasm32", target_os = "android", target_os = "ios")))]
pub fn run_desktop() -> anyhow::Result<()> {
    DesktopApp::<ClipboardState, _>::new(ClipboardScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .run()
}

#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn run_mobile() -> anyhow::Result<()> {
    MobileApp::<ClipboardState, _>::new(ClipboardScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .run()
}

#[cfg(target_os = "android")]
#[no_mangle]
fn android_main(app_handle: AndroidApp) {
    let _ = MobileApp::<ClipboardState, _>::new(ClipboardScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .run_with_android_app(app_handle);
}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub fn run_web() -> Result<(), wasm_bindgen::JsValue> {
    console_error_panic_hook::set_once();
    WebApp::<ClipboardState, _>::new(ClipboardScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .run()
        .map_err(|error| wasm_bindgen::JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":5,"label":"preview/lib.rs","value":"preview-lib-rs"}
mod app;
mod i18n;

use fission::prelude::*;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
    console_error_panic_hook::set_once();
    WebApp::<app::ClipboardState, _>::new(app::ClipboardScreen)
        .with_env(i18n::create_env())
        .with_sync_env(i18n::sync_env)
        .mount("#fission-web-mount")
        .run()
        .map_err(|error| JsValue::from_str(&error.to_string()))
}
{"id":"fission-tabs-1","index":6,"label":"i18n/en-US.yaml","value":"i18n-en-us-yaml"}
clipboard.title: "Share a work reference"
clipboard.explanation: "Copy only the reference you intend to share. Clipboard contents can be visible to other apps."
clipboard.reference: "Reference to share"
clipboard.private_note: "Private note"
clipboard.private_help: "This note stays in this screen. The copy action never reads it."
clipboard.copy: "Copy reference"
clipboard.paste: "Read clipboard text"
clipboard.idle: "Nothing has been copied or read by this screen."
clipboard.writing: "Requesting a copy of the reference…"
clipboard.reading: "Reading clipboard text at your request…"
clipboard.write_accepted: "The host completed the copy request."
clipboard.read_text: "The host returned the text shown below."
clipboard.empty: "The host returned no text."
clipboard.failed: "Clipboard access failed or is unavailable. Your reference and note are unchanged."
clipboard.invalid: "The host returned an unexpected result. Your reference and note are unchanged."
clipboard.last_pasted: "Last successful read"
clipboard.pasted_text: "Clipboard text"
language.english: "English"
language.spanish: "Español"
{"id":"fission-tabs-1","index":7,"label":"i18n/es-ES.yaml","value":"i18n-es-es-yaml"}
clipboard.title: "Comparte una referencia de trabajo"
clipboard.explanation: "Copia solo la referencia que quieras compartir. Otras apps pueden ver el contenido del portapapeles."
clipboard.reference: "Referencia para compartir"
clipboard.private_note: "Nota privada"
clipboard.private_help: "Esta nota permanece en la pantalla. La acción de copiar nunca la lee."
clipboard.copy: "Copiar referencia"
clipboard.paste: "Leer texto del portapapeles"
clipboard.idle: "Esta pantalla no ha copiado ni leído nada."
clipboard.writing: "Solicitando la copia de la referencia…"
clipboard.reading: "Leyendo el portapapeles a petición tuya…"
clipboard.write_accepted: "El host ha completado la solicitud de copia."
clipboard.read_text: "El host ha devuelto el texto que se muestra debajo."
clipboard.empty: "El host no ha devuelto texto."
clipboard.failed: "El acceso al portapapeles ha fallado o no está disponible. La referencia y la nota no cambian."
clipboard.invalid: "El host ha devuelto un resultado inesperado. La referencia y la nota no cambian."
clipboard.last_pasted: "Última lectura correcta"
clipboard.pasted_text: "Texto del portapapeles"
language.english: "Inglés"
language.spanish: "Español"
{"id":"fission-tabs-1"}
Enter a reference and a different private note. Select Copy reference, then Read clipboard text. If the browser allows the operation, only the reference should appear in the result. A rejected operation must show an error rather than pretending text was copied. These buttons intentionally access the real host clipboard; use nonsensitive test text.
Show the app preview
Hide the app preview

2. Keep consent, requests and completions separate

Copying queues WRITE_CLIPBOARD_TEXT with the public reference alone. Reading queues READ_CLIPBOARD_TEXT only after the user's action. Both bind unit completion actions through cx.effects.bind, and their reducers inspect the typed cx.input. The host does not return clipboard contents through a made-up action constructor.
The status prevents overlapping clipboard operations and the real spinner describes pending work. A failure preserves the reference, private note and last successful read. The last-read label matters: keeping an older value without identifying it could imply a failed read returned fresh text.
On iOS, the shell uses UIPasteboard. On Web, the normal host uses the browser's clipboard API, whose secure-context, user-activation and permission rules still apply. A browser or embedded frame can reject access; this example does not bypass that policy. It does not install MemoryClipboardHost.
The current native text provider can retain an in-process fallback when the system clipboard cannot be read, and a write acknowledgement is not an independent cross-app readback. Therefore treat the result as a host operation result, not a verified guarantee that another application can retrieve the text. Verify that behavior separately on the target.
Deny or block clipboard access where the browser permits it, then repeat the action. Your input must remain intact. This is an actual host failure path, not a switch that simulates successful copying.
Show the app preview
Hide the app preview

3. Check the real iOS hand-off

Use the simulator workflow and physical iPhone installation for target setup rather than repeating signing instructions here.
fission doctor ios --project-dir .
fission run --target ios --project-dir .
fission test --target ios --project-dir .
Copy nonsensitive text in the app and paste it into a separate app. Then copy text elsewhere and explicitly read it in this screen. Confirm that an empty clipboard or an access failure does not replace the private note or reference. On an iPhone, check any system paste disclosure rather than assuming the simulator's behavior proves it.
Do not use this flow for passwords, authentication tokens or a promise of clipboard secrecy. The app does not implement an expiry policy, cross-device clipboard restrictions or secure erasure. Its narrower guarantee is visible in the code: the private note is never passed to the copy effect.
Test blank references, rapid presses, a language change and failed reads over a previous successful result. Native, Web and cross-app tests establish different evidence; compilation alone establishes none of the clipboard interactions.