iOS APP内弹窗推送版本更新信息(实现跳转、强制更新等)

发布时间:2024-12-14 11:49

关注版本更新,有些书籍会定期推出新版,选择最新版更全面。 #生活知识# #购物技巧# #图书选购建议#

最新推荐文章于 2022-02-14 17:06:20 发布

weixin_34090562 于 2019-01-09 03:15:17 发布

项目必须要做这个,自己顺便记录一下

- (void)updateVersion:(NSString *)path {

// 获取本地版本号

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

// 取得AppStore信息

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

manager.requestSerializer = [AFJSONRequestSerializer serializer];

[manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];

[manager GET:path parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {

NSLog(@"responseObject --- %@", responseObject);

NSData *dataCast = responseObject;

NSString *dataString = [[NSString alloc] initWithData:dataCast encoding:NSUTF8StringEncoding];

NSData *data =[dataString dataUsingEncoding:NSUTF8StringEncoding];

id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSArray *array = json[@"results"];

// app store 最新版本号

NSString *newVersion;

for (NSDictionary *dic in array) {

newVersion = [dic valueForKey:@"version"];

}

// 取更新日志信息

NSString *changeStr;

for (NSDictionary *dic in array) {

changeStr = [dic valueForKey:@"releaseNotes"];

}

// app store 跳转版本链接

NSString *trackViewUrl;

for (NSDictionary *dic in array) {

trackViewUrl = [dic valueForKey:@"trackViewUrl"];

}

NSLog(@"app store 的更新信息 --- %@, app store 的最新版本号 --- %@, 跳转版本链接 --- %@", changeStr, currentVersion, trackViewUrl);

NSInteger index = [self versionCompareFirst:newVersion andVersionSecond:currentVersion];

// AppStore版本号大于当前版本号,强制更新

if ([self versionCompareFirst:newVersion andVersionSecond:currentVersion] == 0) {

// 弹窗 更新

NSLog(@"");

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;

UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"发现新版本" message:[NSString stringWithFormat:@"新版本%@急需更新",newVersion] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

NSLog(@"");

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];

}];

[alertController addAction:sureAction];

UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

alertWindow.rootViewController = [[UIViewController alloc] init];

alertWindow.windowLevel = UIWindowLevelAlert + 1;

[alertWindow makeKeyAndVisible];

[alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

} else {

// 正常进入程序

[self loadRootVC];

}

NSLog(@"");

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

// 网络异常时,正常进入程序

NSLog(@"");

[self loadRootVC];

}];

}

复制代码

path为AppStore链接:http://itunes.apple.com/cn/lookup?id=(你的Apple ID)

啊啊啊以后不要再说为什么安卓可以实现,而iOS不可以

代码质量有点渣~大家见谅

转载于:https://juejin.im/post/5c3562a0f265da614d095c0d

网址:iOS APP内弹窗推送版本更新信息(实现跳转、强制更新等) https://www.yuejiaxmz.com/news/view/473291

相关内容

PUSH消息推送的实现方法
什么是消息推送?(什么是推送)
springboot整合微信公众号实现模版消息推送
android 消息推送 push
信息推送的方式方法有哪些?(什么是信息推送)
Omni Automation 的出现,让 iOS 版 OmniFocus 和 Mac 版一样强大
APP消息推送(Push)
赶快升级!iOS 14.5.1正式版推送:苹果同步关闭iOS 14.4.2验证
苹果推送iOS 12.4.6:包含重要安全更新、iPhone 5s/6快升
信息推送(信息推送的技术基础)

随便看看