Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
88 stars 9 forks source link

Scanner feature request failed on appBridge 2 #80

Open marco-visualsquares opened 2 years ago

marco-visualsquares commented 2 years ago

Describe the bug

Unable to disptach scanner feature request on IOS POS using shopify appBridge 2

To Reproduce

Sample code to reproduce the behaviour:

    app.featuresAvailable().then((state) => {
      alert(`state.Scanner : ${JSON.stringify(state.Scanner)}`)
      console.log('featuresAvailable scanner', state.Scanner);
      console.log('featuresAvailable', state);

      if (
        state.Scanner[Scanner.Action.OPEN_CAMERA].Dispatch &&
        state.Scanner[Scanner.Action.CAPTURE].Subscribe
      ) {
        this.canAccessCamera = true;
        alert(`canAccessCamera: already true}`)
      } else {
        this.canAccessCamera = false;
        // // Dispatch an action to request access to Scanner actions
        features.dispatch(Features.Action.REQUEST, {
          feature: Group.Scanner,
          action: Scanner.Action.OPEN_CAMERA,
        });
      }
    });

the feature key for shopify appbridege 2 APP::SCANNER::OPEN::CAMERA is not in IOS POS. However android has it

IOS result: Image from iOS android result

Screenshot_20211119-172420_Shopify POS

Expected behaviour

both payload should be the same and feature should be able to dispatch

Contextual information

Packages and versions

List the relevant packages:

Platform

derrickrc commented 2 years ago

I am testing app bridge 2 and also unable to get scanner to work on iOS. When I use the below:

          features.dispatch(Features.Action.REQUEST, {
            feature: Group.Scanner,
            action: Scanner.Action.OPEN_CAMERA
          });
          scanner.dispatch(Scanner.Action.OPEN_CAMERA) 

I get:

Optional Params: [{"version":"2.0.5","group":"Error","type":"APP::ERROR::UNSUPPORTED_OPERATION","payload":{"action":{"group":"Features","type":"APP::FEATURES::REQUEST","payload":{"feature":"Scanner","action":"APP::SCANNER::OPEN::CAMERA","id":"f3cfc79b-7b45-4767-b747-712a07324676"},"version":"2.0.5","clientInterface":{"name":"@shopify/app-bridge","version":"2.0.5"},"source":{"apiKey":"635c3add70ebdf3b81518d25d6acc86b","host":"fjtesting2.myshopify.com/admin","forceRedirect":false}},"id":"f3cfc79b-7b45-4767-b747-712a07324676","type":"APP::ERROR::UNSUPPORTED_OPERATION","message":"Scanner and APP::SCANNER::OPEN::CAMERA are not supported","property":"feature"}}]

When I remove the features.dispatch and try to only use scanner.dispatch, nothing happens and no error is returned.

pramodparanthaman commented 2 years ago

Here's a workaround for this bug.

      features.dispatch(Features.Action.REQUEST, {
        feature: Group.Scanner,
        action: "OPEN::CAMERA", // Work around for app-bridge 2.0 on iOS/iPadOS
      });
      scanner.dispatch(Scanner.Action.OPEN_CAMERA); // Oddly, this works fine
jeffblake commented 2 years ago

I can't get the scanner to appear at all, on iOS, app bridge react 3. No error messages, nothing. Tried all combinations of app bridge 2/3, and React 16/17