By setting requestLongTermAccess: true in the pick options, your app is granted access to the file that persists even after the app or device is restarted.
To use this functionality:
- Set
requestLongTermAccess: true in your pick call. - Check if
result.bookmarkStatus === 'success'. - If successful, retrieve the
result.bookmark (an opaque string). - Store this
bookmark string locally (e.g., in localStorage or a database). - In future sessions, use the stored bookmark to resolve the file URI.
Note: If you need to resolve the bookmark in a custom native module, refer to the Document viewer source for implementation details.
import { pick, types } from '@react-native-documents/picker'
try {
const [result] = await pick({
mode: 'open',
requestLongTermAccess: true,
type: [types.pdf],
})
if (result.bookmarkStatus === 'success') {
const bookmarkToStore = {
fileName: result.name ?? 'unknown name',
bookmark: result.bookmark,
}
// Store the bookmark for future use
localStorage.set('bookmark', JSON.stringify(bookmarkToStore))
} else {
console.error(result)
}
} catch (err) {
// handle error
}