-
-
Save zo0m/abf40dcb31a1f153a5d1 to your computer and use it in GitHub Desktop.
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
/** | |
* The following snippet will ask the user to rate your app the second time they launch it. | |
* It lets the user rate it now, "Remind Me Later" or never rate the app. | |
*/ | |
var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); | |
win.addEventListener('open', checkReminderToRate); | |
win.add(Ti.UI.createLabel({ text: 'This is a simple app that will remind you to rate it.' })); | |
win.open(); | |
function checkReminderToRate() { | |
var now = new Date().getTime(); | |
var remindToRate = Ti.App.Properties.getString('RemindToRate'); | |
if (!remindToRate) { | |
Ti.App.Properties.setString('RemindToRate', now); | |
} | |
else if (remindToRate < now) { | |
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: | |
Ti.App.Properties.setString('RemindToRate', Number.MAX_VALUE); | |
// NOTE: replace this with your own iTunes link; also, this won't WON'T WORK IN THE SIMULATOR! | |
if (Ti.Android) { | |
Ti.Platform.openURL('URL TO YOUR APP IN THE GOOGLE MARKETPLACE'); | |
} | |
else { | |
Ti.Platform.openURL('URL TO YOUR APP IN THE ITUNES STORE'); | |
} | |
break; | |
case 1: | |
// "Remind Me Later"? Ok, we'll remind them tomorrow when they launch the app. | |
Ti.App.Properties.setString('RemindToRate', now + (1000 * 60 * 60 * 24)); | |
break; | |
case 2: | |
Ti.App.Properties.setString('RemindToRate', Number.MAX_VALUE); | |
break; | |
} | |
}); | |
alertDialog.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment