您的位置:首页 > 移动开发

iOS APP版本更新

2016-05-05 11:38 204 查看
iOS APP版本检查更新:

下面的都是废话,是不能通过苹果审核的,APP更新现在直接发

布新版本就好,苹果内部会帮我们搞好。比如你之前发布了1.0版

本,现在想发布1.1版本或者更高的,你就直接在苹果开发者中

心:http://developer.apple.com 上传新版本就好。

iOS8之后用户可以设置连接WiFi后有新版本APP可以自动更新,

也可以手动在iPhone上打开APP Store 来更新,千万不能像下面

那样提醒用户有新版本可更新,那样几乎是不能通过苹果审核

的。

iOS8.0之后,苹果规定APP内不能出现“当前版本”之类的字样,以为iOS8.0之后用户可以设置在连接WiFi的情况下自动更新APP,但有些用户可能并不想更新APP,所以要在APP内提醒用户。

检查更新的步骤:

1.可以写个方法来获取APP Store上APP的版本号: (记得要遵循代理

NSURLConnectionDelegate)

#pragma mark - 是否有新版本

- (void)isNewVersion{

//判断 APP version, id 是自己 app 上架时的 Apple id

NSString *urlStr =@"https://itunes.apple.com/lookup?id=1234567890";

NSURL *url = [NSURLURLWithString:urlStr];

NSURLRequest *request = [NSURLRequestrequestWithURL:url];

[NSURLConnectionconnectionWithRequest:requestdelegate:self];

}

2.在回调方法中进行判断

- (void)connection:(NSURLConnection *)connection didReceiveData:(nonnullNSData
*)data{

NSError *error;

//序列化

id jsonObject = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragmentserror:&error];

NSDictionary *appInfo = (NSDictionary *)jsonObject;

MCLog(@"%@",appInfo);

NSArray *infoContent = [appInfoobjectForKey:@"results"];

NSString *appVersion = [[infoContentobjectAtIndex:0]objectForKey:@"version"];

MCLog(@"APP version is %@",appVersion);

//地址

NSString *trackViewUrlStr = [[infoContentobjectAtIndex:0]objectForKey:@"trackViewUrl"];

//当前版本

NSString *currentVersion = [NSBundlemainBundle].infoDictionary[@"CFBundleShortVersionString"];

MCLog(@"current version is %@",currentVersion);

if (![appVersionisEqualToString:currentVersion]) {

UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@"检查更新"message:[NSStringstringWithFormat:@"发现新版本(%@),是否升级?",appVersion]preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancalAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {

}];

UIAlertAction *confirmAction = [UIAlertActionactionWithTitle:@"升级"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {

//点击升级,跳到APP store进行更新

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:trackViewUrlStr]];

}];

[alertController addAction:cancalAction];

[alertController addAction:confirmAction];

[self.window.rootViewControllerpresentViewController:alertControlleranimated:YEScompletion:nil];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: