iOS子线程操作检测版本更新,有新版本通知用户更新, CheckVersion
iOS子线程操作检测版本更新,有新版本通知用户更新 CheckVersion
一:如何使用:
#import "CheckVersion.h"
//输入你的app在appStore的 id
[CheckVersion check_APP_UPDATE_WITH_APPID:@""];
上述代码写完就可以了,当用户打开app检测到新版本时,为通知用户,更新,并显示最新版本的更新内容;

二:CheckVersion 类
//
// CheckVersion.h
// TopProgressView
//
// Created by cocoajin on 14-1-20.
// Copyright (c) 2014年 www.zhgu.net. All rights reserved.
// #import <Foundation/Foundation.h> extern NSString const *iTnuesApi; @interface CheckVersion : NSObject //+ (instancetype)check; + (NSString *)check_LocalApp_Version; + (void )check_APP_UPDATE_WITH_APPID:(NSString *)appid; @end
//
// CheckVersion.m
// TopProgressView
//
// Created by cocoajin on 14-1-20.
// Copyright (c) 2014年 www.zhgu.net. All rights reserved.
// #import "CheckVersion.h" NSString const *iTnuesApi = @"http://itunes.apple.com/lookup"; #define kTestApp @"http://itunes.apple.com/lookup?id=350962117" //新浪微博 app测试 @implementation CheckVersion + (instancetype)check
{
static CheckVersion *check = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
check = [[CheckVersion alloc]init];
}); return check;
} + (NSString *)check_LocalApp_Version;
{
NSString *localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; return localVersion;
} + (void )check_APP_UPDATE_WITH_APPID:(NSString *)appid
{
__block id JSON = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ), ^{
NSError *dataError = nil;
NSString *appURLAPI = [NSString stringWithFormat:@"%@?id=%@",iTnuesApi,appid];
NSData *appData = [NSData dataWithContentsOfURL:[NSURL URLWithString:appURLAPI] options: error:&dataError];
if (dataError) {
//NSLog(@"appStore app版本信息请求错误!请重新尝试");
[self showAlertWithMessage:@"appStore app版本信息请求错误!请重新尝试"];
return ;
}
JSON = [NSJSONSerialization JSONObjectWithData:appData options: error:nil];
//NSLog(@"ddd : %@",JSON); if ([[JSON objectForKey:@"resultCount"] intValue] > ) {
NSString *remoteVersion = [[[JSON objectForKey:@"results"] objectAtIndex:] objectForKey:@"version"];
NSString *releaseNotes = [[[JSON objectForKey:@"results"] objectAtIndex:] objectForKey:@"releaseNotes"];
NSString *trackURL = [[[JSON objectForKey:@"results"] objectAtIndex:] objectForKey:@"trackViewUrl"];
[[NSUserDefaults standardUserDefaults] setObject:trackURL forKey:@"KK_THE_APP_UPDATE_URL"];
//NSLog(@"%@ %@ %@",remoteVersion,releaseNotes,trackURL); NSString *localVersion = [self check_LocalApp_Version]; if ([remoteVersion floatValue] > [localVersion floatValue]) {
[[CheckVersion check] newVersionUpdate:remoteVersion notes:releaseNotes];
}
else
{
return;
} }
else
{
//NSLog(@"appStore 无app信息,请检查您的 app id");
[self showAlertWithMessage:@"appStore 无此app信息,请检查您的 app id"];
return ;
} }); } + (void)showAlertWithMessage:(NSString *)messages
{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"版本更新提示" message:messages delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show]; #if !__has_feature(objc_arc)
[alert release];
#endif
}); } - (void)newVersionUpdate:(NSString *)version notes:(NSString *)releaseNotes
{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"新版本 %@",version] message:releaseNotes delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新", nil];
[alert show]; #if !__has_feature(objc_arc)
[alert release];
#endif
});
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==) {
//NSString *apiUrl = @"https://itunes.apple.com/us/app/wei-bo/id350962117?mt=8&uo=4";
//apiUrl = @"itms-apps://itunes.apple.com/cn/app/wei-bo/id350962117?mt=8";
NSString *theAppURL = [[NSUserDefaults standardUserDefaults] objectForKey:@"KK_THE_APP_UPDATE_URL"];
NSURL *appStoreURL = [NSURL URLWithString:theAppURL];
[[UIApplication sharedApplication] openURL:appStoreURL];
}
}
@end
iOS子线程操作检测版本更新,有新版本通知用户更新, CheckVersion的更多相关文章
- iOS子线程操作UI问题检查
iOS开发中,因为大部分函数都不是线程安全的,所以UI子线程中操作UI是非常危险的事,但是有时候因为开发者经验不足,不知道子线程中不能UI,或者知道但是写代码的时候没注意,或者不知道那些函数操作UI了 ...
- Android开发——子线程操作UI的几种方法
在Android项目中经常有碰到这样的问题,在子线程中完成耗时操作之后要更新UI,下面就自己经历的一些项目总结一下更新的方法: 在看方法之前需要了解一下Android中的消息机制. 转载请标明出处:h ...
- C# 多线程学习系列四之ThreadPool取消、超时子线程操作以及ManualResetEvent和AutoResetEvent信号量的使用
1.简介 虽然ThreadPool.Thread能开启子线程将一些任务交给子线程去承担,但是很多时候,因为某种原因,比如子线程发生异常.或者子线程的业务逻辑不符合我们的预期,那么这个时候我们必须关闭它 ...
- PyQt5 QSerialPort子线程操作
环境: python3.6 pyqt5 只是简单的一个思路,请忽略脆弱的异常防护: # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets im ...
- iOS子线程更新UI的两种方法
http://blog.csdn.net/libaineu2004/article/details/45368427 方法1:performSelectorOnMainThread[self perf ...
- Android开发——子线程操作UI的几种方法(待续)
方法2 Handler andler mHandler = new Handler() { @Override public void handleMessage(Message msg) { su ...
- 解决子线程操作UI的方法
- iOS应用版本更新(自动提醒用户更新代码)
在#import "AppDelegate.h" 文件中的application:(UIApplication *)application didFinishLaunchingWi ...
- android UI 操作 不要在子线程中操作UI
不管是android ,还是 ios ,请不要在子线程中操作UI,有时有些崩溃,从报错上看不出什么原因,就有可能是子线程操作了UI:切记,切记! 请放在主线程例: activity.runOnUiTh ...
随机推荐
- SpringBoot学习(二)
MyBatis是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架,避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.spring Boot 是能支持快速创建 Spring 应用的 ...
- Python基础篇:从0开始学python
目录 数据类型 基本数据类型 整形Int的内置方法 字符串Str的内置方法 列表(待补充) 流程控制 分支结构if...else... for循环 循环控制 while循环 函数 函数的名称与格式 参 ...
- Wannafly挑战赛17 B
题解 大概就是求证这个 \[\sum_i^nC_{n}^i*C_n^i = C_{2n}^n\] 证明: \[(1+x)^{2n} = [C(0,n)+C(1,n)*x+...+C(n,n)*x^n] ...
- [TJOI2017]DNA --- 后缀数组
[TJOI2017]DNA 题目描述 加里敦大学的生物研究所,发现了决定人喜不喜欢吃藕的基因序列S, 有这个序列的碱基序列就会表现出喜欢吃藕的性状,但是研究人员发现对碱基序列S,任意修改其中不超过3个 ...
- BZOJ 4516: [Sdoi2016]生成魔咒 后缀自动机 性质
http://www.lydsy.com/JudgeOnline/problem.php?id=4516 http://blog.csdn.net/doyouseeman/article/detail ...
- 埃及分数 a* 搜索 知识点mark
题意 在古埃及,人们使用单位分数的和(即1/a,a是自然数)表示一切有理 数. 例如,2/3=1/2+1/6,但不允许2/3=1/3+1/3,因为在加数中不允许有相同的. 对于一个分数a/b,表示方法 ...
- POJ 2406 Power Strings 简单KMP模板 strcmp
http://poj.org/problem?id=2406 只是模板,但是有趣的是一个strcmp的字符串比较函数,学习到了... https://baike.baidu.com/item/strc ...
- bzoj 1779
较水的网络流. /************************************************************** Problem: 1779 User: idy002 L ...
- 二、python的逻辑运算与数据类型
.python的逻辑运算符 数学运算符 加:+ 减:- 乘:* 除:/ 取余:% 关系运算符 等于: == 不等于: != 小于:< 大于:> 大于等于: >= ...
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...