开发者

Rate 5 Stars Reminder with UIAlert

I Was searchin the web for this but finaly made it by myself. Just copy to viewdidload to show the reminder after the app opened the third time

NSArray 开发者_如何转开发*path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
 NSString *documents = [path objectAtIndex:0];
 NSString *counterPath = [documents stringByAppendingPathComponent:@"counter.txt"];
 NSString *number = [NSString stringWithContentsOfFile:counterPath encoding:NSUTF8StringEncoding error:nil];
 int numberint = [number intValue];
 int opens = numberint + 1;
 NSString *dataString = [NSString stringWithFormat:@"%d", opens];
 NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
 [data writeToFile:counterPath atomically:YES];


 if (opens == 3 ) {

  UIAlertView *myAlert = [[UIAlertView alloc]
        initWithTitle:@"*****" message:@"Please Rate 5 Stars to Support MY APP"
        delegate:self 
        cancelButtonTitle:nil
        otherButtonTitles:@"OK",nil];
  [myAlert show];
 }


instead of using text file, you should have used NSDefaults to store the counter value, and just read it on launch. It would have simplified the code a lot.


Rather than build your own solution, why not use an off-the-shelf library to do this?

Like this one for example ;-): https://github.com/nicklockwood/iRate

This lets you configure when the rating prompt will be shown based on number of app launches, number of days installed and a bunch of other parameters, and it takes the user directly to the ratings page on iTunes.


Appirater is a class that you can drop into any iPhone app (iOS 4.0 or later) that will help remind your users to review your app on the App Store. The code is released under the MIT/X11, so feel free to modify and share your changes with the world. Read on below for how to get started. If you need any help using, the library check out the Appirater group.

Configuration

Appirater provides class methods to configure its behavior. See Appirater.h for more information.

[Appirater setAppId:@"552035781"];
[Appirater setDaysUntilPrompt:1];
[Appirater setUsesUntilPrompt:10];
[Appirater setSignificantEventsUntilPrompt:-1];
[Appirater setTimeBeforeReminding:2];
[Appirater setDebug:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜