IOS 更新弹窗提醒(每天提醒一次)

2017-08-23  本文已影响0人  linkon

//每天比较一次

- (void)judgeNeedVersion{

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

NSDate *now = [NSDate date];

NSDate *agoDate = [userDefault objectForKey:@"nowDate"];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy-MM-dd"];

NSString *agoDateString = [dateFormatter stringFromDate:agoDate];

NSString *nowDateString = [dateFormatter stringFromDate:now];

if ([agoDateString isEqualToString:nowDateString]) {

return;

}else

{

NSDate *nowDate = [NSDate date];

NSUserDefaults *dataUser = [NSUserDefaults standardUserDefaults];

[dataUser setObject:nowDate forKey:@"nowDate"];

[dataUser synchronize];

[self shareAppVersion] ;

}

}

//APP更新提醒

- (void)shareAppVersion{

//URL 提取 自己重写 忽略

[HTTPURL getRequest:@"**********" parameters:@{@"*****":@"*****"} success:^(NSURLSessionDataTask *task, id responseObject) {

upDateInfoStr = responseObject[@"updateInfo"];

NSString *appVersionAppStr = responseObject[@"version"];

NSString *localVersionStr = [[[NSBundle mainBundle] infoDictionary]objectForKey:@"CFBundleShortVersionString"];

if ([self judgeNewVersion:appVersionAppStr withOldVersion:localVersionStr]) {

UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"更新提示\n%@",upDateInfoStr] message:@"" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alertVc addAction:action1];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id1064284849?mt=8"]];

}];

[alertVc addAction:action2];

[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:alertVc animated:YES completion:nil];

}

} filure:^(NSURLSessionDataTask *task, id error) {

}];

}

//版本大小判定

- (BOOL)judgeNewVersion:(NSString *)newVersion withOldVersion:(NSString *)oldVersion

{

NSArray *newArray = [newVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];

NSArray *oldArray = [oldVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];

for (NSInteger i = 0; i < newArray.count; i ++) {

if ([newArray[i] intValue] > [oldArray[i] intValue]) {

return YES;

}

}

return NO;

}

上一篇下一篇

猜你喜欢

热点阅读