Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: On IOS Emulator [error] - Error: Uncaught (in promise): Error: Not available on iOS #89

Closed
4 of 10 tasks
danisk89 opened this issue Oct 28, 2023 · 5 comments
Closed
4 of 10 tasks
Labels
bug/fix Something isn't working needs: triage

Comments

@danisk89
Copy link

danisk89 commented Oct 28, 2023

Plugin(s)

  • Barcode Scanning
  • Face Detection
  • Face Mesh Detection
  • Selfie Segmentation
  • Translation

Did you test the latest version?

  • I use the latest version

Platform(s)

  • Android
  • iOS
  • Web

Current behavior

If i try to start a new scan the plugin return me [error] - Error: Uncaught (in promise): Error: Not available on iOS

Expected behavior

I want to use it on iOS. On Android is OK

Reproduction

https://github.com/robingenz/capacitor-mlkit-plugin-demo.git

Steps to reproduce

async scan(): Promise<void> {
    await BarcodeScanner.requestPermissions();

        // Check if the Google ML Kit barcode scanner is available
        await BarcodeScanner.isGoogleBarcodeScannerModuleAvailable().then(async (data) => {
            if (data.available) {
                // Start the barcode scanner
                await this.startScanner().then(async (barcodes) => {
                    var code = barcodes[0].rawValue;
                    console.log(code);
                });
            } else {
                // Install the Google ML Kit barcode scanner
                await BarcodeScanner.installGoogleBarcodeScannerModule().then(async () => {
                    await this.startScanner().then(async (barcodes) => {
                        var code = barcodes[0].rawValue;
                        console.log(code);
                    });
                });
            }
        });
  }

  async startScanner() {
    const { barcodes } = await BarcodeScanner.scan({
        formats: [BarcodeFormat.QrCode, BarcodeFormat.Ean13]
    });
    return barcodes;
}

  async requestPermissions(): Promise<boolean> {
    const { camera } = await BarcodeScanner.requestPermissions();
    return camera === 'granted' || camera === 'limited';
  }

  async presentAlert(): Promise<void> {
    console.log("Non va");
  }

Other information

No response

Capacitor doctor

Latest Dependencies:

@capacitor/cli: 5.5.1
@capacitor/core: 5.5.1
@capacitor/android: 5.5.1
@capacitor/ios: 5.5.1

Installed Dependencies:

@capacitor/cli: 5.4.1
@capacitor/core: 5.4.1
@capacitor/ios: 5.4.1
@capacitor/android: 5.4.1

Before submitting

  • I understand that incomplete issues (e.g. without reproduction) are closed.
@danisk89 danisk89 added bug/fix Something isn't working needs: triage labels Oct 28, 2023
@robingenz
Copy link
Member

isGoogleBarcodeScannerModuleAvailable is not available on iOS, see documentation:

Only available on Android.

Therefore, you should call this method only on Android.

@danisk89
Copy link
Author

Ok, thank you so much. But if i want to use this plugin on ios, how to do? I tried on emulator and doesn't work

@robingenz
Copy link
Member

I am not quiet sure what you mean. You can just call the following method (for example) on iOS:

const scan = async () => {
  const { barcodes } = await BarcodeScanner.scan({
    formats: [BarcodeFormat.QrCode],
  });
  return barcodes;
};

But you should call isGoogleBarcodeScannerModuleAvailable only on Android. Therefore just check the platform, see https://capacitorjs.com/docs/core-apis/web#getplatform

@danisk89
Copy link
Author

Ok thanks a lot!! Should it work on ios xcode emulator?

@robingenz
Copy link
Member

I haven't tried it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/fix Something isn't working needs: triage
Projects
None yet
Development

No branches or pull requests

2 participants