S
S
Sergey Sokolov2021-05-29 15:54:01
JavaScript
Sergey Sokolov, 2021-05-29 15:54:01

How to call native sharing with a file on Safari for iOS?

A web page for mobile, an image is generated in canvas that can be downloaded and saved to the device.

There is also an experimental technology Navigator.share() , and with it it turns out to open a native sharing dialog.

sharing code
cnv.toBlob((blob) => {
  const file = new File([blob], filename, {type: blob.type}); // PNG by default
  share(file);
})

const share = (file) => {
  const filesArray = [file];

  if (navigator.canShare && navigator.canShare({ files: filesArray })) {
    navigator.share({
      files: filesArray,
      title: 'Hello',
      text: 'World',
    })
    .then(() => errorLog('Share was successful.'))
    .catch((error) => errorLog('Sharing failed: ' + error));
  } else {
    errorLog(`Your system doesn't support sharing files.`);
  }
}


It works on Android, but on iPhones with iOS 14, file sharing fails the navigator.canShare() check . If the file is removed, text sharing works.

Is there any way to open the native system file sharing dialog (PNG images) in apple devices?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question