使用 UIAlert 评价 5 星提醒
我在网上搜索这个,但最终自己做到了。只需复制到viewdidload即可在应用程序第三次打开后显示提醒
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];
}
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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用 NSDefaults 来存储计数器值,而不是使用文本文件,并在启动时读取它。它会大大简化代码。
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.
与其构建自己的解决方案,为什么不使用现成的库来执行此操作呢?
例如这个;-): https://github.com/nicklockwood/iRate
这可以让你配置何时根据应用程序启动次数、安装天数和一堆其他参数显示评级提示,并将用户直接带到 iTunes 上的评级页面。
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 是一个类,您可以将其放入任何 iPhone 应用程序(iOS 4.0 或更高版本)中,以帮助提醒您的用户在 App Store 上评论您的应用程序。该代码是在 MIT/X11 下发布的,因此请随意修改并与世界分享您的更改。请阅读下文了解如何开始。如果您需要任何使用帮助,请查看图书馆的 Appirater 小组。
Configuration
Appirater 提供类方法来配置其行为。有关详细信息,请参阅 Appirater.h。
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.