#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
typedef enum : NSUInteger {
stateRefusal=1, // 殘忍拒絕
stateComplaints, //我要吐槽
statePraise //好評(píng)
} lastSelectStateEunm;
@interface QPushToAppStore : NSObject
+ (QPushToAppStore*)sharePushToAppStpre;
- (void)showGotoAppStore;
@end
#import "QPushToAppStore.h"
#import <StoreKit/StoreKit.h>
//判斷時(shí)間 點(diǎn)擊了對(duì)應(yīng)的按鈕所需的天數(shù) 下次彈出appstore對(duì)話框
#define ShowRefusalDay 2 //殘忍拒絕相隔時(shí)間
#define ShowComplaintsDay 8 //我要吐槽相隔時(shí)間
#define ShowPraiseDay 16 //好評(píng)相隔時(shí)間
#define APPSTORE_UEL @"itms-apps://itunes.apple.com/idxxxxxxxx?&mt=8" //AppStore相應(yīng)地址
//上傳打開時(shí)間
NSString *const LastOpenData = @"lastOpenData";
//上次版本
NSString *const LastVersion = @"LastVersion";
//上傳選擇狀態(tài)
NSString *const LastSelectState = @"LastSelectState";
@interface QPushToAppStore()<SKStoreProductViewControllerDelegate> {
UIAlertController *alertController;
}
@property (nonatomic,copy) NSString *title;
@property (nonatomic,copy) NSString *message;
@end
@implementation QPushToAppStore
+ (QPushToAppStore*)sharePushToAppStpre {
static QPushToAppStore *sharedObject = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (!sharedObject) {
sharedObject = [[[self class] alloc] init];
}
});
return sharedObject;
}
- (void)showGotoAppStore {
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
//當(dāng)前版本
CGFloat currentVerson = [infoDict[@"CFBundleShortVersionString"] floatValue];
//上次打開的時(shí)間 上次打開的版本 上次選擇的選項(xiàng)
NSDate *lastOpenDate = [userDefault objectForKey:LastOpenData];
CGFloat lastVersion = [userDefault floatForKey:LastVersion];
NSString *lastSelectState =[userDefault stringForKey:LastSelectState];
//存儲(chǔ)打開的時(shí)間 和 版本
[userDefault setFloat:currentVerson forKey:LastVersion];
[userDefault synchronize];
if (lastOpenDate == nil || currentVerson != lastVersion) {
//第一次打開 和 當(dāng)前版本不對(duì)應(yīng)(證明客戶升級(jí)版本了)
[userDefault setObject:[NSDate date] forKey:LastOpenData];
[userDefault removeObjectForKey:LastSelectState];
return;
}
//比較時(shí)間值
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *component = [calendar components:NSCalendarUnitDay fromDate:lastOpenDate toDate:[NSDate date] options:0];
NSInteger disDay = component.day;
//判斷用戶上一次選擇的狀態(tài)
//1殘忍拒絕
//2我要吐槽
//3我要贊贊
if (lastSelectState) {
NSInteger lastSelectStateInt = [lastSelectState integerValue];
if ((lastSelectStateInt == stateRefusal && disDay >= ShowRefusalDay) || (lastSelectStateInt == stateComplaints && disDay >= ShowComplaintsDay) || (lastSelectStateInt == statePraise && disDay >= ShowPraiseDay)) {
//保存時(shí)間
[self alertUserCommentView];
}
} else {
if (disDay >= ShowRefusalDay) {
[self alertUserCommentView];
}
}
}
- (void)alertUserCommentView {
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
alertController = [UIAlertController alertControllerWithTitle:self.title message:self.message preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@"??殘忍拒絕" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
[userDefault setInteger:stateRefusal forKey:LastSelectState];
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"??好評(píng)贊賞" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
[userDefault setInteger:statePraise forKey:LastSelectState];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:APPSTORE_UEL]];
// [self evaluate];
}];
UIAlertAction *showAction = [UIAlertAction actionWithTitle:@"??我要吐槽" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
[userDefault setInteger:stateComplaints forKey:LastSelectState];
//跳轉(zhuǎn)到AppStore
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:APPSTORE_UEL]];
// [self evaluate];
}];
[alertController addAction:refuseAction];
[alertController addAction:okAction];
[alertController addAction:showAction];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
}
//系統(tǒng)內(nèi)部進(jìn)入AppStore
- (void)evaluate {
SKStoreProductViewController *storeProdutVC = [[SKStoreProductViewController alloc]init];
storeProdutVC.delegate = self;
[storeProdutVC loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@"1142134162"} completionBlock:^(BOOL result, NSError * _Nullable error) {
if (error) {
NSLog(@"error %@ with userInfo %@",error,[error userInfo]);
} else {
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:storeProdutVC animated:YES completion:nil];
}
}];
}
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController{
[[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
}
- (NSString *)title {
return _title == nil ? @"致用戶的一封信":_title;
}
- (NSString *)message {
return _message == nil ? @"有了您的支持才能更好的為您服務(wù),提供更加優(yōu)質(zhì)的,更加適合您的App,當(dāng)然您也可以直接反饋問題給到我們":_message;
}
- (void)dealloc {
NSLog(@"%s",__func__);
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[QPushToAppStore sharePushToAppStpre] showGotoAppStore];
});
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。