# tauri-plugin-ios-bookmark
iOS security-scoped bookmark plugin for Tauri 2.
This plugin provides a native bridge for opening files from the iOS Files app,
creating persistent security-scoped bookmarks, reading bookmarked files later,
and forgetting saved bookmarks.
This crate is intended for Tauri 2 mobile apps that target iOS. The Rust crate
registers the native plugin, while the guest JavaScript API exposes a small
command surface for your frontend.
## Features
- `pickAndBookmark`: presents `UIDocumentPickerViewController`, reads the file,
and returns a bookmark identifier plus file metadata
- `readByBookmark`: resolves a previously saved bookmark and reads the file again
- `forgetBookmark`: removes a stored bookmark
## Package Layout
- `src/`: Rust plugin entrypoints and mobile bridge
- `ios/`: Swift implementation for the iOS native plugin
- `guest-js/`: TypeScript guest API entrypoint
- `permissions/`: default Tauri permission definitions
## Install
Add the Rust crate to your Tauri app:
```bash
cargo add tauri-plugin-ios-bookmark
```
Install the guest JavaScript API in your frontend package:
```bash
npm install tauri-plugin-ios-bookmark-api
```
The guest package expects `@tauri-apps/api` from your Tauri application.
## Rust Setup
Register the plugin in your Tauri builder:
```rust
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_ios_bookmark::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
## JavaScript Usage
The guest API exposes three commands:
```ts
import {
forgetBookmark,
pickAndBookmark,
readByBookmark,
} from 'tauri-plugin-ios-bookmark-api'
const picked = await pickAndBookmark()
const targetedPick = await pickAndBookmark({
targetPath: '/docs/related.md',
})
console.log(picked.bookmarkId)
console.log(picked.fileName)
console.log(picked.filePath)
console.log(picked.content)
console.log(targetedPick.bookmarkId)
const reread = await readByBookmark(picked.bookmarkId)
console.log(reread.fileName)
console.log(reread.content)
await forgetBookmark(picked.bookmarkId)
```
`pickAndBookmark()` returns:
```ts
type PickBookmarkRequest = {
targetPath?: string
suggestedFileName?: string
}
type PickResult = {
bookmarkId: string
fileName: string
filePath?: string
content: string
}
```
When `targetPath` is supplied, the plugin performs exact-file validation after the user picks a file. If the selected file does not match the requested target, the command rejects instead of creating a bookmark for the wrong file.
`readByBookmark()` returns:
```ts
type ReadResult = {
fileName: string
content: string
}
```
## Permissions
The default permission set enables all plugin commands.
Available permissions are documented in
`permissions/autogenerated/reference.md` and include:
- `ios-bookmark:allow-pick-and-bookmark`
- `ios-bookmark:allow-read-by-bookmark`
- `ios-bookmark:allow-forget-bookmark`
## Platform Notes
- This plugin is iOS-only.
- The file picker is backed by `UIDocumentPickerViewController`.
- If `targetPath` is provided, the plugin uses it as best-effort picker context and enforces exact-file validation after selection.
- Bookmarks are intended for persistent access to user-selected files.
- On unsupported platforms, initialization returns an unsupported error path.