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 ...
随机推荐
- 关于python安全性的问题
收集总结了一下python安全方面的知识点以及近年来的相关漏洞,如果有需要修正或补充的地方,欢迎各位师傅的指出. 常见web漏洞在python中的示例. xss python下的xss其原理跟php是 ...
- 安卓 onTouch OnTouchEvent onChick 顺序
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 分发触摸事件 -> 在 触摸 时候 -> 在触摸事件时候->在点击时候 ...
- HDU 1011 Starship Troopers 树形+背包dp
http://acm.hdu.edu.cn/showproblem.php?pid=1011 题意:每个节点有两个值bug和brain,当清扫该节点的所有bug时就得到brain值,只有当父节点被 ...
- bzoj 2045: 双亲数
2045: 双亲数 Description 小D是一名数学爱好者,他对数字的着迷到了疯狂的程度. 我们以d = gcd(a, b)表示a.b的最大公约数,小D执著的认为,这样亲密的关系足可以用双亲来描 ...
- Makefile-有三个非常有用的变量。分别是$@,$^,$<代表的意义
$@ 代表目标文件,$^ 代表所有的依赖文件,$< 代表第一个依赖文件. # 这是简化后的Makefilemain:main.o mytool1.o mytool2.o gcc -o $@ $^ ...
- bzoj 3784
第三道点分治. 首先找到黄学长的题解,他叫我参考XXX的题解,但已经没有了,然后找到另一个博客的简略题解,没看懂,最后看了一个晚上黄学长代码,写出来然后,写暴力都拍了小数据,但居然超时,....然后改 ...
- MySQL数据库单例连接简单实现(MySQL扩展)
<?php /** * MySQL数据库单例实现 * * @author shizq at 2015-04-22 * */ final class MySQLFactory { private ...
- PAT甲级1076. Forwards on Weibo
PAT甲级1076. Forwards on Weibo 题意: 微博被称为中文版的Twitter.微博上的一位用户可能会有很多关注者,也可能会跟随许多其他用户.因此,社会网络与追随者的关系形成.当用 ...
- WPF中的导航框架(一)——概述
有的时候,我们需要一个支持页面跳转的UI,例如文件浏览器,开始向导等.对于这样的界面,简单的可以使用ContentControl + ContentTemplateSelector的方式来实现,但是有 ...
- 腾讯PHP工程师面试题两份
试题一: PHP开发工程师笔试试卷 姓名:__________ 一.PHP开发部分 1.合并两个数组有几种方式,试比较它们的异同 2.请写一个函数来检查用户提交的数据是否为整数(不区分数据类型,可以为 ...