Closed Danchat5 closed 8 months ago
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.
Please see the Contributing Guide for how to create a Code Reproduction.
Thanks! Ionitron 💙
I also attempted getPhoto() instead of pickImages(), and I encountered the same error (does not work the first time, works every consecutive attempt). Seems to be the same issue as this one.
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.
Please see the Contributing Guide for how to create a Code Reproduction.
Thanks! Ionitron 💙
I have been able to replicate the error in a standalone app. You can view it here, where both getPhoto() and pickImages() do nothing the first time they are clicked on an iOS device. Any other time they are clicked, the menu will pop up as expected. This was tested on both an iPhone and an iPad.
Please, can you provide the source code? The url is not enough, we need to be able to run it and make changes to verify we have fixed the issue.
Alright, here you go:
homeComponent.ts
import { Component } from '@angular/core';
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'
import { HttpClient } from '@angular/common/http'
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(public http: HttpClient, private readonly domSanitizer: DomSanitizer) { }
img: any
async pickImage() {
const newPhotos = await Camera.pickImages({
quality: 100,
limit: 1,
correctOrientation: true
})
if (newPhotos.photos.length > 0) {
try {
let p = newPhotos.photos.pop()
//format of p: blob http://hash
console.log(p?.webPath)
if (p?.webPath) {
this.img = this.domSanitizer.bypassSecurityTrustUrl(p?.webPath)
}
} catch (e) {
console.error(e)
}
}
}
async getPhoto() {
const photo = await Camera.getPhoto({
resultType: CameraResultType.Uri,
quality: 100,
correctOrientation: true,
source: CameraSource.Photos
})
if(photo?.webPath) {
this.img = this.domSanitizer.bypassSecurityTrustUrl(photo.webPath)
}
}
}
homeComponent.html
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>
Camera Test
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<ion-fab horizontal="center" slot="fixed">
<button (click)="pickImage()">
pickImages()
</button>
</ion-fab>
<ion-fab >
<button horizontal="center" (click)="getPhoto()">
getPhoto()
</button>
</ion-fab>
<img [src]="img">
</ion-content>
The plugins that are installed are above in my original post. I can post the whole project in a zip file later if need be.
That's still not enough, we need a .zip or a public github repository that we can download
Here's the project in a zip file: SelectImageDemo.zip
Thanks for the sample app, I've been able to reproduce. This is not an iOS bug but a Safari bug, and only affects web platform on Safari browser (both desktop and mobile). Native iOS works fine.
I just tested on Google Chrome and Firefox on my iPhone and I'm getting the same issue.
How do you test it natively on iOS?
On iOS/iPadOS all browsers use "Safari" (WebKit) under the hood.
For testing natively you can follow this https://capacitorjs.com/docs/ios
Where do you recommend I bring up this issue? I haven't dealt with Safari bugs before.
It’s a bug in camera plugin that only affects safari, so we will look into it and try to fix it.
@jcesarmobile Any updates on this bug?
We are experiencing the same issue, on safari the user is required to click twice before being able to select an image. Any update on this bug? Or, is there a workaround available?
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.
Bug Report
Plugin(s)
"@capacitor/camera": "^4.1.1"
Capacitor Version
4.0.1
Platform(s)
web
Current Behavior
When the pickImages() function runs, the option menu on iOS (that gives the options Gallery, Take Picture, or Files) does not appear the first time. Every consecutive time the function is called, it works as intended.
Code Reproduction
You can view a test app here where I try out both pickImages() and getPhoto() functions.
Additional Context
This appears to be a near duplicate of this issue, except for the fact that Android was the offending platform. I ensured that the plugin that caused the issue on that problem was not installed in my application.
I will list the plugins I am using below: