在iPhone App中提醒用户打分或写评价的方法

用户使用了软件却不到 App Store 打分或是写评论是很令开发者头疼的。下面这个方法能在 iPhone App 中集成提醒功能,弹出文字框来提示没有打分的用户。

主要代码

[[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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值