实用工具iOS 开发继续加油准备看的

一句话实现iOS版本更新提示

2018-02-09  本文已影响822人  SelwynBee

在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]];
}
上一篇 下一篇

猜你喜欢

热点阅读