IOS 添加评论功能

跳转到APPStore评分页

	[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=XXXXXX&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];
		[self.storeProduct setNotRequest];

 

跳转到软件首页

NSString *str2 = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",  @"XXXXXX"]; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str2]];


其中的XXXXXX部分为itunesconnect中的应用程序id。


跳转条件 

必须同时满足程序启动十五次以上 安装七天以上

#import <Foundation/Foundation.h>
#import "FMDB.h"
@interface SqlLiteSKStoreProduct : NSObject
//判断是否弹出评论框
-(BOOL)isTanchu;
//设置以后不再弹出评论
-(void)setNotRequest;
//重置程序重启的次数
-(void)resetStartTimes;
//程序启动次数加1
-(void)addRestartTimes;
@end

<pre name="code" class="objc">#import "SqlLiteSKStoreProduct.h"
@interface SqlLiteSKStoreProduct()
@property FMDatabase *database;
@end
@implementation SqlLiteSKStoreProduct
-(id)init{
	self=[super init];
	[self openSKStoreProductDatabase];
	[self createLoginInfoTable];
	return self;
}

-(void)dealloc{
	[_database commit];
	[_database close];
}

-(BOOL) openSKStoreProductDatabase{
	//获取Document文件夹下的数据库文件,没有则创建
	NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
	NSString *dbPath = [docPath stringByAppendingPathComponent:@"SKStoreProduct.db"];
	//获取数据库并打开
	self.database  = [FMDatabase databaseWithPath:dbPath];
	if (![self.database open]) {
		NSLog(@"Open database failed");
		return NO;
		self.database=nil;
	}
	else{
		return YES;
	}
}

-(BOOL) createLoginInfoTable{
	if (self.database!=nil) {
		return [self.database executeUpdate:@"create table if not exists storeProduct(id INTEGER PRIMARY KEY,installDate date,startTimes int,request bool)"];
	}
	else{
		return NO;
	}
}
-(BOOL)isTanchu{
	if (self.database!=nil) {
		FMResultSet *resultSet1 = [self.database executeQuery:@"select * from storeProduct"];
		if (resultSet1!=nil && ![resultSet1 next]) {
			NSNumber * intNumber=[NSNumber numberWithInt:1];
		   [self.database executeUpdateWithFormat:@"insert into storeProduct(installDate,startTimes,request) values (%@,%@,%d)",[NSDate date],intNumber,YES];
		   return NO;
		}
		NSDate* installDate=nil;
		int restartTimes=0;
		int ID=-1;
		FMResultSet *resultSet = [self.database executeQuery:@"select * from storeProduct"];
		while ([resultSet next]) {
			BOOL requestBool =[resultSet boolForColumn:@"request"];
			if (!requestBool) {
				return NO;
			}
			installDate = [resultSet dateForColumn:@"installDate"];
			restartTimes= [resultSet intForColumn:@"startTimes"];
			ID=[resultSet intForColumn:@"id"];
			break;
		}
		NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
		NSDate * curDate=[NSDate date];
		NSUInteger unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit | NSYearCalendarUnit;
		NSDateComponents *components = [gregorian components:unitFlags fromDate:installDate toDate:curDate options:0];
		long days=[components day];
		if (days > 7 && restartTimes >15) {
			return YES;
		} else {
			return NO;
		}
	}
	else{
		return NO;
	}

}
-(void)setNotRequest{
	if (self.database!=nil) {
		FMResultSet *resultSet1 = [self.database executeQuery:@"select * from storeProduct"];
		if (resultSet1!=nil && ![resultSet1 next]) {
			NSNumber * intNumber=[NSNumber numberWithInt:1];
			[self.database executeUpdateWithFormat:@"insert into storeProduct(installDate,startTimes,request) values (%@,%@,%d)",[NSDate date],intNumber,NO];
			return ;
		}
		int ID=0;
		FMResultSet *resultSet = [self.database executeQuery:@"select * from storeProduct"];
		while ([resultSet next]) {
			ID= [resultSet intForColumn:@"id"];
			break;
		}
		[self.database executeUpdateWithFormat:@"update storeProduct set request = %d where id = %d",NO,ID];
    }
}
-(void)resetStartTimes{
	if (self.database!=nil) {
		FMResultSet *resultSet1 = [self.database executeQuery:@"select * from storeProduct"];
		if (resultSet1!=nil && ![resultSet1 next]) {
			NSNumber * intNumber=[NSNumber numberWithInt:1];
			[self.database executeUpdateWithFormat:@"insert into storeProduct(installDate,startTimes,request) values (%@,%@,%d)",[NSDate date],intNumber,YES];
			return ;
		}
		int ID=0;
		FMResultSet *resultSet = [self.database executeQuery:@"select * from storeProduct"];
		while ([resultSet next]) {
			ID= [resultSet intForColumn:@"id"];
			break;
		}
		NSNumber * intNumber=[NSNumber numberWithInt:1];
		[self.database executeUpdateWithFormat:@"update storeProduct set startTimes = %@ where id = %d",intNumber,ID];
	}
}
-(void)addRestartTimes{
	if (self.database!=nil) {
		FMResultSet *resultSet1 = [self.database executeQuery:@"select * from storeProduct"];
		if (resultSet1!=nil && ![resultSet1 next]) {
			NSNumber * intNumber=[NSNumber numberWithInt:1];
			[self.database executeUpdateWithFormat:@"insert into storeProduct(installDate,startTimes,request) values (%@,%@,%d)",[NSDate date],intNumber,YES];
			return ;
		}
		int ID=0;
		FMResultSet *resultSet = [self.database executeQuery:@"select * from storeProduct"];
		int restartTimes=0;
		while ([resultSet next]) {
			restartTimes= [resultSet intForColumn:@"startTimes"];
			ID= [resultSet intForColumn:@"id"];
			restartTimes++;
			break;
		}
		NSNumber * intNumber=[NSNumber numberWithInt:restartTimes];
		[self.database executeUpdateWithFormat:@"update storeProduct set startTimes = %@ where id = %d",intNumber,ID];
	}
}
@end


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值