在App開發過程中,難免會碰到類似于添加版本更新提示這種開發需求。如何更簡單更快捷的實現版本更新提示,便成了重中之重。本文主要介紹了如何通過一句話去快捷實現iOS版本更新提示,歡迎Star!
github地址: https://github.com/RockChanel/SELUpdateAlert
SELUpdateAlert.gif
1. 添加方式
主要通過以下兩種方式為我們的App添加版本更新提示。至于如何獲取版本號以及更新內容,例如服務器獲取或AppStore獲取方式,網上已經有很多介紹,這里就不再加以闡述。
/**
添加版本更新提示
@param version 版本號
@param descriptions 版本更新內容(數組)
descriptions 格式如 @[@"1.xxxxxx",@"2.xxxxxx"]
*/
+ (void)showUpdateAlertWithVersion:(NSString *)version Descriptions:(NSArray *)descriptions;
/**
添加版本更新提示
@param version 版本號
@param description 版本更新內容(字符串)
description 格式如 @"1.xxxxxx\n2.xxxxxx"
*/
+ (void)showUpdateAlertWithVersion:(NSString *)version Description:(NSString *)description;
調用方式如下:
/** 添加更新提示 */
//方法一:
[SELUpdateAlert showUpdateAlertWithVersion:@"1.0.0" Descriptions:@[@"1.xxxxxxxxxx",@"2.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",@"3.xxxxxxxxxx",@"4.xxxxxxxxxx"]];
//方法二:
//[SELUpdateAlert showUpdateAlertWithVersion:@"1.0.0" Description:@"1.xxxxxxxxxx\n2.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n3.xxxxxxxxx\n4.xxxxxxxxxx"];
2. 出場入場動畫實現
入場動畫:
/**
添加Alert入場動畫
@param alert 添加動畫的View
*/
- (void)showWithAlert:(UIView*)alert{
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = SELAnimationTimeInterval;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[alert.layer addAnimation:animation forKey:nil];
}
出場動畫:
/** 添加Alert出場動畫 */
- (void)dismissAlert{
[UIView animateWithDuration:SELAnimationTimeInterval animations:^{
self.transform = (CGAffineTransformMakeScale(1.5, 1.5));
self.backgroundColor = [UIColor clearColor];
self.alpha = 0;
}completion:^(BOOL finished) {
[self removeFromSuperview];
} ];
}
3. 修改App id
在點擊更新跳轉AppStore,需要跳轉自己應用在AppStore頁面,需要自己去設置App id.
/** App id */
#define APP_ID @"11111111"
/** 更新按鈕點擊事件 跳轉AppStore更新 */
- (void)updateVersion
{
NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%@", APP_ID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}