QQ等APP版本更新(iOS)

作者: Devil雅馨 | 来源:发表于2016-08-17 11:03 被阅读392次
每个APP都会涉及版本更新的问题,所以APP每次启动有新版本的话都会提示版本更新,和新功能

下面我们来看一下效果图:


做的有点粗糙, 不过呢该实现的都有了, 有强迫症的朋友可以多多注意细节问题哈😘

//
//  ViewController.m
//  Version update
//
//  Created by dllo on 16/8/17.
//  Copyright © 2016年 高雅馨. All rights reserved.
//

#import "ViewController.h"
// 这里我们要签一个提示框的协议
@interface ViewController ()<UIAlertViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *updateInfo=@"";
    NSString *message = [NSString stringWithFormat:@"%@\n",updateInfo];
    message=@"--1.增加了添加好友功能。--\n--2.增加了添加好友功能和评论点赞功能。--\n--3.增加了添加好友功能。--\n--4.增加了添加好友功能和评论点赞功能论点赞功能。--\n";//使用中此行注释
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"有新版本发布啦!" message:message delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"前往更新", nil];
    // [strongSelf willPresentAlertView:alertView];//此方法iOS 7.0之后就不能用
    alertView.tag=1243;
    //如果你的系统大于等于7.0
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
        // CGSize size = [message sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(240, 400) lineBreakMode:NSLineBreakByCharWrapping];//ios7之后废弃了
        CGRect size=[message boundingRectWithSize:CGSizeMake(240, 400) options:NSStringDrawingUsesFontLeading attributes:nil context:nil];
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 240, size.size.height)];
        textLabel.font = [UIFont systemFontOfSize:15];
        textLabel.textColor = [UIColor blackColor];
        textLabel.backgroundColor = [UIColor clearColor];
        textLabel.lineBreakMode = NSLineBreakByCharWrapping;
        textLabel.numberOfLines = 0;
        textLabel.textAlignment = NSTextAlignmentLeft;
        // textLabel.layer.borderWidth=1;
        // textLabel.layer.borderColor=[UIColor grayColor].CGColor;
        textLabel.text = message;
        [alertView setValue:textLabel forKey:@"accessoryView"];
        //这个地方别忘了把alertview的message设为空
        alertView.message = @"";
    }
    [alertView show];
}
// 这里是我在Main.storyboard里约束的一个button
- (IBAction)UpdateBtnClick:(UIButton *)sender {
    [self versionUpdate];
}
- (void)versionUpdate {
    //获得当前发布的版本
    //    __weak typeof(self) weakSelf=self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //        typeof(self) strongSelf=weakSelf;
        // 耗时的操作---获取某个应用在AppStore上的信 息,更改id就行
        NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/lookup?id="] encoding:NSUTF8StringEncoding error:nil];
        if (string!=nil) {
            NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
            NSString *version = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"version"];
            NSString *updateInfo = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"releaseNotes"];
            //获得当前版本
            NSString *currentVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
                if ( version &&![version isEqualToString:currentVersion]) {
                    //有新版本
                    NSString *message = [NSString stringWithFormat:@"%@\n",updateInfo];
                    message=@"--1.增加了添加好友功能。--\n--2.增加了添加好友功能。--\n2.增加了添加好友功能。\n--3.增加了添加好友功能。--\n--4.增加了添加好友功能。--\n";//使用中此行注释
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"有新版本发布啦!" message:message delegate:self cancelButtonTitle:@"忽略" otherButtonTitles:@"前往更新", nil];
                    //  [strongSelf willPresentAlertView:alertView];//此方法iOS 7.0之后就不能用
                    alertView.tag=1243;
                    //如果你的系统大于等于7.0
                    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
                        // CGSize size = [message sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(240, 400) lineBreakMode:NSLineBreakByCharWrapping];//ios7之后废弃了
                        CGRect size=[message boundingRectWithSize:CGSizeMake(240, 400) options:NSStringDrawingUsesFontLeading attributes:nil context:nil];
                        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 240, size.size.height)];
                        textLabel.font = [UIFont systemFontOfSize:15];
                        textLabel.textColor = [UIColor blackColor];
                        textLabel.backgroundColor = [UIColor clearColor];
                        textLabel.lineBreakMode = NSLineBreakByCharWrapping;
                        textLabel.numberOfLines = 0;
                        textLabel.textAlignment = NSTextAlignmentLeft;
                        // textLabel.layer.borderWidth=1;
                        //  textLabel.layer.borderColor=[UIColor grayColor].CGColor;
                        textLabel.text = message;
                        [alertView setValue:textLabel forKey:@"accessoryView"];
                        //这个地方别忘了把alertview的message设为空
                        alertView.message = @"";
                    }
                    [alertView show];
                }else{
                    //已是最高版本
                    // NSLog(@"已经是最高版本");
                }
            });
        }
    });
}
/*根据被点击按钮的索引处理点击事件--当被按钮被点击了这里做出一个反馈*/
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1 && alertView.tag==1243)
    {
        //您的APP链接
        NSString *url = @"https://itunes.apple.com/cn/";
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

希望对大家有所帮助(づ ̄ 3 ̄)づ🙈

相关文章

  • QQ等APP版本更新(iOS)

    每个APP都会涉及版本更新的问题,所以APP每次启动有新版本的话都会提示版本更新,和新功能 下面我们来看一下效果图...

  • iOS版本更新

    iOS APP版本 更新

  • 5.26跃评运营晚报

    QQ 8.0.5 iOS版更新:支持聊天消息界面长截图 昨日,QQ推送了iOS版的8.0.5版本更新。新版本迎来了...

  • ReactNative App更新下载(Android+iOS)

    APP涉及到版本更新(非热更新),版本检测下载App,Android和iOS实现方式不同 1.Android直接和...

  • iOS APP版本更新

    比较版本 APP判断是否有新版本,一般有两种方法,一种是将本地版本号作为参数传给服务器,由后台判断当前用户的APP...

  • iOS app版本更新

    楼主主要接触了俩种更新方式,一种是服务器端配置,app直接获取到服务器返回的version值,同本地的versio...

  • 关于iOS 中App 证书更新的一些事情

    iOS 中线上的App 可以分为企业版本和App Store版本 企业版的更新 现象:iOS企业版证书到期导致AP...

  • 关于iOS 中App 证书更新的一些事情

    iOS 中线上的App 可以分为企业版本和App Store版本 企业版的更新 现象:iOS企业版证书到期导致AP...

  • iOS获取基本信息

    iOS获取设备型号和App版本号等信息 // 获取当前App的基本信息字典 //app名称 // app版本 //...

  • App提示更新bug

    问题描述:App提示更新,但是等更新以后发现实际根本没更新,还是原先的版本,App还是在提示更新,结果继续更新,等...

网友评论

本文标题:QQ等APP版本更新(iOS)

本文链接:https://www.haomeiwen.com/subject/skjmsttx.html