您的位置:首页 > 移动开发

[IPhone] 如何在iphone app中提醒用户Rank或Review

2010-11-28 20:52 501 查看
Introduction

How can we remind user to review or rank in App?

We can show a alert box to remind user to review, I writed a sample code using singleton to remind user.

How to use

[[CloudReview sharedReview]reviewFor:395519376];





CloudReview.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface CloudReview : NSObject {
	int m_appleID;
}
+(CloudReview*)sharedReview;
-(void) reviewFor:(int)appleID;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
@end





CloudReview.m

#import "CloudReview.h"

@implementation CloudReview
static CloudReview* _sharedReview = nil;
+(CloudReview*)sharedReview
{
	@synchronized([CloudReview class])
	{
		if (!_sharedReview)
			[[self alloc] init];
		
		return _sharedReview;
	}
	
	return nil;
}
+(id)alloc
{
	@synchronized([CloudReview class])
	{
		NSAssert(_sharedReview == nil, @"Attempted to allocate a second instance of a singleton.");
		_sharedReview = [super alloc];
		return _sharedReview;
	}
	
	return nil;
}
-(void)reviewFor:(int)appleID
{
	m_appleID = appleID;
	BOOL neverRate = [[NSUserDefaults standardUserDefaults] boolForKey:@"neverRate"];
	if(neverRate != YES) {
		//Show alert here
		UIAlertView *alert;
		alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"rate_title",@"Rate My Appication")
										   message:NSLocalizedString(@"rate_main",@"Please Rate my Application")
										  delegate: self
								 cancelButtonTitle:NSLocalizedString(@"rate_cancel",@"Cancel")
								 otherButtonTitles: NSLocalizedString(@"rate_now",@"Rate Now"),
				 NSLocalizedString(@"rate_never",@"Never Rate"), nil];
		[alert show];
		[alert release];
	}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
	// Never Review Button
	if (buttonIndex == 2)
	{
		[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"neverRate"];
	}
	// Review Button
	else if (buttonIndex == 1)
	{
		[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"neverRate"];
		NSString *str = [NSString stringWithFormat:
				@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
				m_appleID ]; 
		NSLog(str);
		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
	}
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: