-
-
Save psyked/1992356 to your computer and use it in GitHub Desktop.
"Rate my app in Appcelerator Titanium Mobile" as a commonJS module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RateMe(ios_url, goog_url, usecount) { | |
if(!Ti.App.Properties.hasProperty('RemindToRate')) { | |
Ti.App.Properties.setString('RemindToRate', 0); | |
} | |
var remindCountAsInt = parseInt(Ti.App.Properties.getString('RemindToRate'), 10); | |
var newRemindCount = remindCountAsInt += 1; | |
if(remindCountAsInt === -1) { | |
// the user has either rated the app already, or has opted to never be | |
// reminded again. | |
return false; | |
} else if(remindCountAsInt < usecount) { | |
Ti.App.Properties.setString('RemindToRate', newRemindCount); | |
} else if(remindCountAsInt >= usecount) { | |
var alertDialog = Titanium.UI.createAlertDialog({ | |
title : 'Please rate this app!', | |
message : 'Would you take a moment to rate this app?', | |
buttonNames : ['OK', 'Remind Me Later', 'Never'], | |
cancel : 2 | |
}); | |
alertDialog.addEventListener('click', function(evt) { | |
switch (evt.index) { | |
case 0: | |
// "Ok" - open the appropriate rating URL, and set flag to never | |
// ask again | |
Ti.App.Properties.setString('RemindToRate', -1); | |
if(Ti.Android) { | |
Ti.Platform.openURL(goog_url); | |
} else { | |
Ti.Platform.openURL(ios_url); | |
} | |
break; | |
case 1: | |
// "Remind Me Later"? Ok, we'll reset the current count to zero | |
Ti.App.Properties.setString('RemindToRate', 0); | |
break; | |
case 2: | |
// "Never" - Set the flag to -1, to never ask again | |
Ti.App.Properties.setString('RemindToRate', -1); | |
break; | |
} | |
}); | |
alertDialog.show(); | |
} | |
} | |
function iOSURLFromAppId(appId) { | |
return 'itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=' + appId + '&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software'; | |
} | |
function googURLFromAppId(appId) { | |
return 'market://details?id=' + appId; | |
} | |
exports.checkNow = RateMe; | |
exports.iOSURLFromAppId = iOSURLFromAppId; | |
exports.googURLFromAppId = googURLFromAppId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RateMe = require('RateMe'); | |
var iOSURL = RateMe.iOSURLFromAppId('384080636'); | |
var googURL = RateMe.googURLFromAppId('couk.mmtdigital.orion.ianrankin'); | |
RateMe.checkNow(iOSURL, googURL, 1); |
I forked and made changes to fix the problem that I was seeing: https://gist.github.com/jakeorr/6032340
@jakeorr correct! had the same issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @psyked correct me if I'm wrong, but shouldn't the line:
var newRemindCount = remindCountAsInt += 1;
be something like:
var newRemindCount = remindCountAsInt + 1;
If you increment
remindCountAsInt
at the same time as assigning it tonewRemindCount
, the "never" flag will not be respected.