Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
Ionic Capacitor - Screenshot to Gallery (iOS)

Haven't been able to find any solution to this.

I'm using Ionic Framework 5+ and using Capacitor 3+.

I need to be able to have the user take a screenshot on iOS and Android and have that screenshot automatically saved to the users photo gallery. Android works just fine with the following code. iOS also works, however it saves the file in a temporary directory so I need to move the file to whatever directory it needs to go to on iOS so the user can see it in their photo gallery.

import { Screenshot } from '@ionic-native/screenshot/ngx';

this.screenshot.save('jpg', 80).then((res) => {
  this.filePath = res.filePath;
  console.log(this.filePath);
});

Is there a way to use the FileSystem Capacitor API to save this photo at this this.filePath to the iOS gallery?

Is there another way to go from screenshot to gallery on iOS?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

On iOS the gallery is something external from your app and can't be accessed through the Filesystem plugin because there is no path to it (and even if there was, iOS apps are sandboxed, you can't access other apps, only your app contents)

You can save a native UIImage to the gallery with this native code:

UIImageWriteToSavedPhotosAlbum(yourImage, nil, nil, nil) but you have a native path, not an UIImage, so you'll have to convert the path to UIImage first, with something like let yourImage = UIImage.init(contentsOfFile: imagePath). So, with that code you can create a plugin that send the path and saves the image to the gallery.

You can also search for plugins that already do that. There is this one that saves a base64 string that represents an image into the gallery https://ionicframework.com/docs/native/base64-to-gallery

There is also capacitor-community/media that has a savePhoto function, which takes a path and saves the photo to the gallery

https://github.com/capacitor-community/media#api

over 4 years ago · Santiago Trujillo Relatório

0

This works for iOS. I'm using it in production at the moment. The fundamental problem had to do with the fact that the Capacitor Community Media library wasn't documented very well to specify exact formatting needed to make it work. This is the working package.json version of the library: "@capacitor-community/media": "github:dragermrb/media".

this.screenshot.save().then(async (res) => {

  const savePhotoResult = await Media.savePhoto({
    path: `file://${res.filePath}`,
    album: this.album.identifier
  });
});
over 4 years ago · Santiago Trujillo Relatório

0

How do you do the installation of @ionic-native/screenshot/ngx and the plugin itself, if you use capacitor, I'm a bit lost with that

about 4 years ago · Daniel Acosta Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda