dpa99c / cordova-launch-review

Cordova/Phonegap plugin for iOS and Android to assist in leaving user reviews/ratings in the App Stores
71 stars 26 forks source link

New 4.0.0 rating(result) is returning 0, dialog not opening. #26

Closed rolinger closed 3 years ago

rolinger commented 3 years ago

Bug report

CHECKLIST

Current behavior:

This is breaking on v4.0.0 on Android versions 7 - 10, but older version 3.1.1 still works on v7 - 10. I don't have an Android 11 device (yet) to test on so I don't know the behavior for v11.

Result is returning value 0, not opening dialog but also causing external app review to not launch. LaunchReview.rating(function(result) { // result = 0, unexpected }

Expected behavior:

On Android, using old v3.1.1 advanced code or the new v4.0.0 advanced code, rating result returns value while also not prompting for dialog box or launching external app store review. Condition 0 is not an expected response.

Steps to reproduce:

var MAX_DIALOG_WAIT_TIME = 5000; //max time to wait for rating dialog to display
var ratingTimerId;

LaunchReview.rating(function(result){
     console.log(result) ;   // value is 0, android does nothing.
     if(cordova.platformId === "ios"){
        if(result === "requested"){
            console.log("Requested display of rating dialog");

            ratingTimerId = setTimeout(function(){
                console.warn("Rating dialog was not shown (after " + MAX_DIALOG_WAIT_TIME + "ms)");
            }, MAX_DIALOG_WAIT_TIME);
        }else if(result === "shown"){
            console.log("Rating dialog displayed");

            clearTimeout(ratingTimerId);
        }else if(result === "dismissed"){
            console.log("Rating dialog dismissed");
        }
    } else if(cordova.platformId === "android"){
        console.log("Rating dialog displayed");  // console msg prints, but nothing happens.
    } 

},function(err){
    console.log("Error opening rating dialog: " + err);
});

To fix, I had to add:

    } else if(cordova.platformId === "android"){
        console.log("Rating dialog displayed");   // but nothing happens
        if (result === 0) {
           // call extneral launch function
           $scope.rateAppLaunch() ;
        }
    } 
rolinger commented 3 years ago

For android, here is my fix:

    LaunchReview.rating(function(result){
      if (cordova.platformId === "android"){
        if (result === 0) {
          errMgmt("menu/rateApp",2601.3,"Android: In-App Review failed, opening store review.") ;      
          $scope.rateAppStore() ;          
        } else {
          errMgmt("menu/rateApp",2601.4,"Android: In-App Review opened.") ;      
        }
      } else if(cordova.platformId === "ios"){
        if (result === "requested"){
          ratingTimerId = setTimeout(function(){
          $scope.rateAppStore() ;
          }, MAX_DIALOG_WAIT_TIME);
        } else if (result === "shown"){
          errMgmt("menu/rateApp",2601.5,"iOS: In-App Review opened.") ;      
          clearTimeout(ratingTimerId);
        } else if (result === "dismissed"){
        } else {
          // default open app store review
          errMgmt("menu/rateApp",2601.6,"iOS: In-App Review failed, opening store review.") ;      

        }
      }
    },function(err){
      errMgmt("menu/rateApp",2601.7,"In-App Review function failed, opening store review.") ;      
      $scope.rateAppStore() ;     
    });
  }
panderium-art commented 3 years ago

The same thing happened to me on Android. I'm receiving status == 0 and dialog is not opening. I tested on Galaxy Note 10, Android 10.

Packages version:

cordova: 8.1.2,
cordova-android: 7.1.2,
cordova-ios: 5.1.1,
cordova-launch-review: 4.0.0

Code usage:

const LaunchReview: LaunchReviewPlugin = window.LaunchReview;
const platformId = window.cordova && window.cordova.platformId;

const IOS: string = 'ios';
const ANDROID: string = 'android';
const MAX_DIALOG_WAIT_TIME: number = 5000;
let ratingTimerId: NodeJS.Timeout;

export const cordovaDriver = {
    rating: () => new Promise((resolve, reject) => {
        LaunchReview.rating((status => {
            if (platformId === ANDROID) {
                const message = 'Rating dialog displayed';
                resolve({status: PROMPT_DISPLAY_STATUS.SHOWN, message})
            }else if (platformId === IOS) {
                if (status === PROMPT_DISPLAY_STATUS.REQUESTED) {
                    ratingTimerId = setTimeout(() => {
                        const message = `Rating prompt was not shown after ${MAX_DIALOG_WAIT_TIME}ms`;
                        reject( message);
                    }, MAX_DIALOG_WAIT_TIME);
                } else if (status === PROMPT_DISPLAY_STATUS.SHOWN) {
                    clearTimeout(ratingTimerId);
                    const message = 'Rating prompt was shown';
                    resolve({status: PROMPT_DISPLAY_STATUS.SHOWN, message})
                }
            }
        }), (err) => {
            const errMessage = `Error opening rating prompt: ${err}`;
            reject(errMessage);
        });
    }),
}

Calling this method by:

export async function showAppRatingPrompt () {
    // Service-level method
    try {
        return await cordovaDriver.rating()
    }catch (err) {
        console.error(`[ LAUNCH REVIEW SERVICE ] ${err}`)
    }
}
dpa99c commented 3 years ago

Will take a look into this when I get a moment

Wunderkemmer commented 3 years ago

I'm integrating this module and I'm also seeing the same 0 result for android, as described above in the first example, with the same code.

dpa99c commented 3 years ago

Just published a fix for this issue in v4.0.1

See updated documentation and example project for reference.