iOS开发企业版应用版本更新的实现

1.代码的实现

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions

                   :(NSDictionary *)launchOptions

{

 

    if ([self checkVersion])

    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"有新版本请更新" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新", nil];

        [alert show];

        [alert release];

    }

    

    return YES;

}


//检查版本号  判断是否需要更新

- (BOOL)checkVersion

{

    //当前的版本号

    NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];

    //    获取服务器的版本号

    NSString *serverUrl = @"https://网址/文件名.plist";

    NSURL * url = [NSURL URLWithString:serverUrl];

    NSURLRequest * request = [NSURLRequest requestWithURL:url];

    NSError * error = nil;

    NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];

    if (data != nil)

    {

        NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMask,YES);

        //存储的路径  真机测试下 document问价后面加/如下/TCal.plist

        NSString *pathPath = [[documentPaths objectAtIndex:0] stringByAppendingString:@"/文件的名字.plist"];

        if ([data writeToFile:pathPath atomically:YES])

        {

            NSDictionary *dic = [[NSDictionary alloc] initWithContentsOfFile:pathPath];

            if (dic)

            {

                NSArray *array = [dic objectForKey:@"items"];

                NSDictionary *metadata = [array[0] objectForKey:@"metadata"];

                //服务器版本号

                NSString *serverVersion = [metadata objectForKey:@"bundle-version"];

                //比较版本号  判断是否需要更新

                if (currentVersion.floatValue < serverVersion.floatValue)

                {

                    return YES;

                }

                else

                {

                    return NO;

                }

            }

            else

            {

                NSLog(@"数据为空");

            }


        }

        else

        {

            NSLog(@"save fail");

        }

    }

    else

    {

        NSLog(@"error : %@",error);

    }

}


#pragma mark --- 更新的弹出视图的代理方法


//警告框

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex == 1 )

    {

        //下载地址 可以是plist文件 

        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"itms-services://?action=download-manifest&url=https://网址/文件名.plist"]];

    }

    

}


2.打包

 



3.放置到服务器上


  将plist文件和spa包放到服务器上







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值