javascriptiosreactjsmacosnext.js

How to export structured notes (image + text) from a Next.js app to Apple Notes?


I'm developing a Next.js application where users can take notes on pictures, and I'm looking for a way to allow users to export these notes (structured as image + text pairs) directly to Apple Notes. So far, I've tried several approaches, but none seem ideal. I'm hoping someone can suggest better solutions or improvements.

Question:

Has anyone encountered a similar situation or found a better way to export structured data (like image + text) to Apple Notes from a web app? Are there any workarounds or other APIs that might support this kind of integration?

Any guidance or suggestions would be greatly appreciated!

Here are the options I've tried so far:

Copy and Paste:

I copy the information (text + image) to the user's clipboard. They can manually paste this into Apple Notes.

Issue: This solution is not very user-friendly and requires manual intervention.

URL Scheme (Only works for text):

iPhone: mobilenotes://add?title=My%20Note%20Title&content=This%20is%20the%20body%20of%20the%20note%20on%20iOS

Mac: notes://add?title=My%20Mac%20Note%20Title&content=This%20is%20the%20body%20of%20the%20note%20on%20macOS

Issue: This only allows text export; images cannot be included using this approach.

Using the Share API:

This allows the user to select Apple Notes as the app where the content will be saved. It works well but has limitations.

Issue: The Share API can only handle a structure like: one title, one text block and then the images in a combination (but not text - image, text - image blocks ... etc.


Solution

  • Using Navigator: clipboard

    It is possible to save html to the clipboard.

    1. Format the notes in a structured html
    2. Create a button with a click event
    3. In this click event use the structured html and navigator.clipboard.write to save the html into the users clipboard
    4. The User will now be able to paste the content into their notes and they will be formatted perfectly.

    Small Code Example

        // first create the clipboard item - use .then to fetch the data because otherwise it will not work on ios
        const clipboardItem = new ClipboardItem({
            'text/html': getYourContent().then((htmlContent) => {
                return new Blob([htmlContent], { type: 'text/html' });
            }),
        });
    
        navigator.clipboard.write([clipboardItem]);
    
    
        const getYourContent = () => {
            // fetch content if you really use this
            // small html example:
            const htmlContent = `
                  <h1>Header</h1>
                  <p>$paragraph</p>
                  <br/>
                  <img src="https:/picture.com" />
            `;
            
            return htmlContent
        }