Beispiel #1
0
    void Init()
    {
        //Set app information for UniRate
        if (string.IsNullOrEmpty(appStoreCountry))
        {
            appStoreCountry = UniRatePlugin.GetAppStoreCountry();
            UniRateDebug.Log("Get Country Code: " + appStoreCountry);
        }
        if (string.IsNullOrEmpty(applicationVersion))
        {
            applicationVersion = UniRatePlugin.GetApplicationVersion();
            UniRateDebug.Log("Get App Version: " + applicationVersion);
        }
        if (string.IsNullOrEmpty(applicationName))
        {
            applicationName = UniRatePlugin.GetApplicationName();
            UniRateDebug.Log("Get App Name: " + applicationName);
        }
        if (string.IsNullOrEmpty(applicationBundleID))
        {
            applicationBundleID = UniRatePlugin.GetApplicationBundleID();
            UniRateDebug.Log("Get Bundle ID: " + applicationBundleID);
        }

        if (string.IsNullOrEmpty(marketPackageName))
        {
            marketPackageName = UniRatePlugin.GetPackageName();
            UniRateDebug.Log("Get Android package name: " + marketPackageName);
        }

        _promptShowing = false;

        UniRateLauched();
    }
Beispiel #2
0
    /// <summary>
    /// Check the conditions to determine UniRate should show the prompt for rating.
    /// </summary>
    /// <returns><c>true</c>, if should prompt for rating, <c>false</c> otherwise.</returns>
    public bool ShouldPromptForRating()
    {
        if (previewMode)           //preview mode?
        {
            Debug.Log("UniRate is in preview mode. Make sure you set previewMode to false when release.");
            return(true);
        }
        else if (this.ratedThisVersion)             //is this version rated?
        {
            UniRateDebug.Log("Not prompt. The user has already rated this version");
            return(false);
        }
        else if (!promptAgainForEachNewVersion && this.ratedAnyVersion)             //is already rated?
        {
            UniRateDebug.Log("Not prompt. The user has already rated for some version and promptAgainForEachNewVersion is disabled");
            return(false);
        }
        else if (this.declinedThisVersion)             //is user refused to rate this version?
        {
            UniRateDebug.Log("Not prompt. The user refused to rate this version");
            return(false);
        }
        else if ((this.daysUntilPrompt > 0.0f || this.usesPerWeekForPrompt != 0.0f) && this.firstUsed == DateTime.MaxValue)             //check for first launch
        {
            UniRateDebug.Log("Not prompt. First launch");
            return(false);
        }
        else if ((DateTime.Now - this.firstUsed).TotalSeconds < this.daysUntilPrompt * SECONDS_IN_A_DAY)
        {
            UniRateDebug.Log("Not prompt. App was used less than " + this.daysUntilPrompt + " days ago");
            return(false);
        }
        else if (this.usesCount < this.usesUntilPrompt)                 //check use times and event times
        {
            UniRateDebug.Log("Not prompt. App was only used " + this.usesCount + " times");
            return(false);
        }
        else if (this.eventCount < this.eventsUntilPrompt)
        {
            UniRateDebug.Log("Not prompt. Only " + this.eventCount + " times of events logged");
            return(false);
        }
        else if (this.usesPerWeek < this.usesPerWeekForPrompt)                  //check if usage frequency high enough
        {
            UniRateDebug.Log("Not prompt. Only used " + this.usesPerWeek + " times per week");
            return(false);
        }
        else if (this.lastReminded != DateTime.MaxValue &&
                 (DateTime.Now - this.lastReminded).TotalSeconds < remindPeriod * SECONDS_IN_A_DAY)
        {
            UniRateDebug.Log("Not prompt. The user askd to be reminded and it is not the time now");
            return(false);
        }

        //It should prompt to rate.
        return(true);
    }
Beispiel #3
0
    void UniRateUserWantRemind()
    {
        UniRateDebug.Log("User wants to be reminded later");
        _promptShowing    = false;
        this.lastReminded = DateTime.Now;

        if (OnUserWantReminderToRate != null)
        {
            OnUserWantReminderToRate();
        }
    }
Beispiel #4
0
    void UniRateUserDeclinedPrompt()
    {
        UniRateDebug.Log("User declined the prompt");
        _promptShowing           = false;
        this.declinedThisVersion = true;

        if (OnUserDeclinedToRate != null)
        {
            OnUserDeclinedToRate();
        }
    }
Beispiel #5
0
    void ReadyToPrompt()
    {
        //Ask the delegate if we can prompt, if there is a delegate.
        if (ShouldUniRatePromptForRating != null && !ShouldUniRatePromptForRating())
        {
            UniRateDebug.Log("Not display prompt because ShouldUniRatePromptForRating returns false.");
            return;
        }

        ShowPrompt();
    }
Beispiel #6
0
 /// <summary>
 /// Opens the rate page directly without automatically configuration. Do not call this
 /// if you did not set the AppID for UniRate yourself. You may want to use RateIfNetworkAvailable()
 /// instead, which can retrive the correct AppiD if the network is available.
 /// </summary>
 public void OpenRatePage()
 {
     this.ratedThisVersion = true;
             #if UNITY_IOS
     UniRateDebug.Log("Open rating page of URL: " + this.RatingIOSURL);
     Application.OpenURL(this.RatingIOSURL);
             #elif UNITY_ANDROID
     UniRateDebug.Log("Open rating page of URL: " + this.RatingAndroidURL);
     UniRatePlugin.OpenAndroidRatePage(this.RatingAndroidURL);
             #elif UNITY_WP8
     UniRateDebug.Log("Open rating page for WP8");
     UniRatePlugin.OpenWPMarket();
             #endif
 }
Beispiel #7
0
    void UniRateUserWantToRate()
    {
        UniRateDebug.Log("User wants to rate");
        _promptShowing = false;

        if (OnUserAttemptToRate != null)
        {
            OnUserAttemptToRate();
        }

        if (ShouldUniRateOpenRatePage != null && !ShouldUniRateOpenRatePage())
        {
            UniRateDebug.Log("Not open rate page because ShouldUniRateOpenRatePage() returning false");
        }
        else
        {
            OpenRatePage();
        }
    }
Beispiel #8
0
    /// <summary>
    /// Shows the prompt, there is no check for conditions or app information getting.
    /// It depends on <see cref="appStoreID"/>, if you are not set it yourself, do not use this metod (use PromptIfNetworkAvailable instead).
    /// </summary>
    public void ShowPrompt()
    {
        UniRateDebug.Log("It's time to show prompt");
        if (OnPromptedForRating != null)
        {
            OnPromptedForRating();
        }

        if (!useCustomizedPromptView)
        {
            UniRatePlugin.ShowPrompt(this.MessageTitle,
                                     this.Message,
                                     this.RateButtonLabel,
                                     this.CancelButtonLabel,
                                     this.RemindButtonLabel);
            _promptShowing = true;
            #if UNITY_WP8
            _shouldPoll = true;
            #endif
        }
    }
Beispiel #9
0
    //This check is only for iOS
    IEnumerator CheckForConnectivityInBackground(bool showPrompt)
    {
        string iTunesServiceURL = "";

        if (!string.IsNullOrEmpty(appStoreCountry))
        {
            iTunesServiceURL = string.Format(kUniRateAppLookupURLFormat, appStoreCountry + "/");
        }
        else
        {
            iTunesServiceURL = string.Format(kUniRateAppLookupURLFormat, "");
        }

        if (appStoreID != 0)
        {
            iTunesServiceURL = iTunesServiceURL + "?id=" + appStoreID;
        }
        else
        {
            iTunesServiceURL = iTunesServiceURL + "?bundleId=" + applicationBundleID;
        }
        UniRateDebug.Log("Checking app info: " + iTunesServiceURL);

        bool errorHappened = false;

        WWW www = new WWW(iTunesServiceURL);

        yield return(www);

        if (String.IsNullOrEmpty(www.error))           //No error. Try parse app info from the returned text
        {
            UniRateAppInfo info = new UniRateAppInfo(www.text);
            if (info.validAppInfo)
            {
                if (info.bundleId.Equals(this.applicationBundleID))                     //Everything goes ok
                {
                    if (appStoreID == 0)
                    {
                        appStoreID = info.appID;
                        UniRateDebug.Log("UniRate found the app, app id: " + appStoreID);
                    }
                    if (this.onlyPromptIfLatestVersion && !this.previewMode)
                    {
                        if (!applicationVersion.Equals(info.version))
                        {
                            UniRateDebug.Log("No prompt because it is not the version in app store and you set onlyPromptIfLatestVersion.");
                            errorHappened = true;
                            UniRateFailWithError(Error.NotTheLatestVersion);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("The bundle Id is not the same. Appstore: " + info.bundleId + " vs AppSetting:" + applicationBundleID);
                    errorHappened = true;
                    UniRateFailWithError(Error.BundleIdDoesNotMatchAppStore);
                }
            }
            else
            {
                if (appStoreID != 0)                   //We have a specified app id
                {
                    Debug.LogWarning("No App info found with this app Id " + appStoreID);
                    errorHappened = true;
                    UniRateFailWithError(Error.AppNotFoundOnAppStore);
                }
                else
                {
                    Debug.Log("No App info found with this bundle Id " + applicationBundleID);
                    Debug.Log("Could not find your app on AppStore. It is normal when your app is not released, don't worry about this message.");
                }
            }
        }
        else
        {
            UniRateDebug.Log("Error happend in loading app information. Maybe due to no internet connection.");
            errorHappened = true;
            UniRateFailWithError(Error.NetworkError);
        }

        //Every thing goes ok. Prompt to rating now.
        if (!errorHappened)
        {
            _currentChecking = false;
            if (showPrompt)
            {
                ReadyToPrompt();
            }
            else
            {
                OpenRatePage();
            }
        }
    }