pushandplay / cordova-plugin-apprate

This plugin provide the "rate this app" functionality into your Cordova/Phonegap application
Apache License 2.0
300 stars 190 forks source link

Opening file:///android_asset/www/null #307

Open bzimbelman opened 3 years ago

bzimbelman commented 3 years ago

I have the following react/cordova app:

import "./App.css";
import React, { useState } from "react";
import AppRate from "cordova-plugin-apprate";

function App() {
  console.log(`App starting...`);

  const handleClick = () => {
    console.log(`handleClick`);
    const ref = window.open("http://www.google.com", "_self");
    console.log(`opened window`);
  };

  const rateClick = () => {
    console.log(`rateClick`);
    AppRate.setPreferences({
      storeAppUrl: {
        ios: "blah.blah.blah",
        android: "market://details?id=blah.blah.blah",
      },
      reviewType: {
        ios: "AppStoreReview",
        android: "inAppBrowser",
      },
      simpleMode: true,
      showPromptForInAppReview: false,
      customLocale: {
        title: "My Title",
        message: "My Message",
        rateButtonLabel: "Rate It Now...",
        cancelButtonLabel: "No, Thanks...",
        laterButtonLabel: "Remind Me Later...",
      },
      callbacks: {
        onButtonClicked: function (buttonIndex) {
          console.log(`Button Clicked ${buttonIndex}`);
          switch (buttonIndex) {
            case 1:
              console.log(`B1`);
              break;
            case 2:
              console.log(`B2`);
              break;
            case 3:
              console.log(`B3`);
              break;
          }
        },
      },
      openUrl: function (url) {
        console.log(`openUrl to ${url}`);
        let safariAvailable = false;
        if (window.SafariViewController) {
          window.SafariViewController.isAvailable(function (available) {
            safariAvailable = available;
          });
        }
        if (!safariAvailable) {
          console.log(`no safari, must be a droid...`);
          window.open(url, "_blank", "location=yes");
        } else {
          window.SafariViewController.show(
            {
              url: url,
              barColor: "#0000ff", // on iOS 10+ you can change the background color as well
              controlTintColor: "#00ffff", // on iOS 10+ you can override the default tintColor
              tintColor: "#00ffff", // should be set to same value as controlTintColor and will be a fallback on older ios
            },
            // this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
            function (result) {},
            function (msg) {}
          );
        }
      },
    });
    AppRate.promptForRating();
  };

  return (
    <div className="App">
      <header className="App-header">
        <p>Hello from React App</p>
        <button onClick={handleClick}>Open Google</button>
        <button onClick={rateClick}>Rate Me</button>
      </header>
    </div>
  );
}

export default App;

When the Rate Me button is clicked, the expected behavior occurs, i.e. the following options are displayed:

Screen Shot 2021-04-29 at 4 31 42 PM

However, when I select the 'Rate It Now...' button I get:

Screen Shot 2021-04-29 at 4 31 59 PM

Which is not the expected behavior. From everything I have read about this, I should see the in-app rating.

Also the log messages do show that openUrl is called with null as the argument and that button 3 was clicked. I assume button 3 is the rate button but that the null value for the url is incorrect.

I did try changing the reviewType.android value from "InAppBrowser" to "InAppReview" but the behavior was the same. I have the following plugins installed: cordova-plugin-apprate cordova-plugin-dialogs cordova-plugin-inappbrowser cordova-plugin-nativestorage cordova-plugin-whitelist