1,登录成功,后台发给最新的版本号,名称,最新内容,然后与当前应用的版本作比较,如有新版本,弹出提示,同时链接到新颁布的appstore url下载更新替换之。
2,非常简单的实现方式:
获取本机的版本
NSDictionary *infoDictionary = [[NSBundlemainBundle] infoDictionary];
NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
,然后解析Apple网站的 版本号,直接对比,不一样就让他升级。
从http://itunes.apple.com/lookup?id=<Your app ID>得到JSON数据,里面包含版本信息,比较一下就可以了。
(关于这个app ID:去apple上填写发布程序时,会生成app id)
得到的json数据:苹果会返回应用对应的所有信息,直接在登录请求时,保存这些版本信息,如有更新时,直接使用提示就行了,(点击链接到appStore)不过记得每次更新时把本地的版本号(变量)更新了。
3,利用apple的push服务,实现颁布更新的功能。这个需要利用push 服务,目前我应用还不太需要push 消息,所以没有接触过,等以后再补充把。
步骤:1.新建一个项目;安装platform :ios, '7.0'
pod "AFNetworking", "2.0.0"
pod 'KissXML', '~> 5.0'
相关类库
2.
//
// ViewController.m
// KissXML
//
// Created by zbh on 14-8-22.
// Copyright (c) 2014年 zbh. All rights reserved.
//
#import "ViewController.h"
#import "AFHTTPRequestOperationManager.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://itunes.apple.com/lookup?id=861183156" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@"JSON: %@", responseObject);
NSArray *app=[responseObject objectForKey:@"results"];
NSDictionary *dic=[app lastObject];
NSString *version1=[dic objectForKey:@"version"];
NSLog(@"%@",version1);
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSLog(@"%@",version);
if (version1>version) {
NSLog(@"升级");
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"请升级软件" delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"确认", nil];
[alert show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString* msg = [[NSString alloc] initWithFormat:@"您按下的第%d个按钮!",buttonIndex];
NSLog(@"%@",msg);
if (buttonIndex==1) {
NSLog(@"OKO");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/sue-rong-shang-hai-zheng-quan/id861183156?mt=8"]];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end