We all know that good reviews for our apps will influence new users to download the app. It doesn’t help that there is no standard way to ask users for a review. The only way to get your app reviewed is on your app page within the App Store. How many people after downloading your app will again go back to AppStore, search for your app, go to rate screen and give you a rating? Not many outside of your own family and friends!

If you prompt the customer at some point while the app is running you’re always going to disrupt their workflow to some degree. You can alleviate this by trying to pick a moment that’s the least disruptive. If possible choose a moment when something positive or rewarding has just happened.

Below is a tutorial to help you add a Rate Me alert view in Swift.

Setup Rate Me

The method below will control the logic of when the Rate Me alert view is displayed to the user. Enter in the minimum number of sessions the app should be opened before showing the request to rate the app the first time and how often it should try again if the user selects “Maybe Later”. The numLaunches and neverRate values are stored using NSUserDefaults.

var iMinSessions = 3 var iTryAgainSessions = 6 func rateMe() { var neverRate = NSUserDefaults.standardUserDefaults().boolForKey("neverRate") var numLaunches = NSUserDefaults.standardUserDefaults().integerForKey("numLaunches") + 1 if (!neverRate && (numLaunches == iMinSessions || numLaunches >= (iMinSessions + iTryAgainSessions + 1))) { showRateMe() numLaunches = iMinSessions + 1 } NSUserDefaults.standardUserDefaults().setInteger(numLaunches, forKey: "numLaunches") }

Using UIAlertController in Swift

UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead. Now UIAlertController is a single class for creating and interacting with what we knew as UIAlertViews and UIActionSheets on iOS 8.

If you would like to use UIAlertView with multiple actions, the method below is the best way to handle each button tapped. The advantage of using completion handlers is you can easily handle multiple alert views within a single view controller.

func showRateMe() { var alert = UIAlertController(title: "Rate Us", message: "Thanks for using ", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Rate ", style: UIAlertActionStyle.Default, handler: { alertAction in UIApplication.sharedApplication().openURL(NSURL(string : "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id= ")) alert.dismissViewControllerAnimated(true, completion: nil) })) alert.addAction(UIAlertAction(title: "No Thanks", style: UIAlertActionStyle.Default, handler: { alertAction in NSUserDefaults.standardUserDefaults().setBool(true, forKey: "neverRate") alert.dismissViewControllerAnimated(true, completion: nil) })) alert.addAction(UIAlertAction(title: "Maybe Later", style: UIAlertActionStyle.Default, handler: { alertAction in alert.dismissViewControllerAnimated(true, completion: nil) })) self.presentViewController(alert, animated: true, completion: nil) }

If you just need an alert view with a single action “Ok”, the following code will do.

let alert = UIAlertView() alert.title = "Alert" alert.message = "Here's a message" alert.addButtonWithTitle("Understod") alert.show()