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的更多相关文章

  1. iOS子线程操作UI问题检查

    iOS开发中,因为大部分函数都不是线程安全的,所以UI子线程中操作UI是非常危险的事,但是有时候因为开发者经验不足,不知道子线程中不能UI,或者知道但是写代码的时候没注意,或者不知道那些函数操作UI了 ...

  2. Android开发——子线程操作UI的几种方法

    在Android项目中经常有碰到这样的问题,在子线程中完成耗时操作之后要更新UI,下面就自己经历的一些项目总结一下更新的方法: 在看方法之前需要了解一下Android中的消息机制. 转载请标明出处:h ...

  3. C# 多线程学习系列四之ThreadPool取消、超时子线程操作以及ManualResetEvent和AutoResetEvent信号量的使用

    1.简介 虽然ThreadPool.Thread能开启子线程将一些任务交给子线程去承担,但是很多时候,因为某种原因,比如子线程发生异常.或者子线程的业务逻辑不符合我们的预期,那么这个时候我们必须关闭它 ...

  4. PyQt5 QSerialPort子线程操作

    环境: python3.6 pyqt5 只是简单的一个思路,请忽略脆弱的异常防护: # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets im ...

  5. iOS子线程更新UI的两种方法

    http://blog.csdn.net/libaineu2004/article/details/45368427 方法1:performSelectorOnMainThread[self perf ...

  6. Android开发——子线程操作UI的几种方法(待续)

    方法2  Handler andler mHandler = new Handler() { @Override public void handleMessage(Message msg) { su ...

  7. 解决子线程操作UI的方法

  8. iOS应用版本更新(自动提醒用户更新代码)

    在#import "AppDelegate.h" 文件中的application:(UIApplication *)application didFinishLaunchingWi ...

  9. android UI 操作 不要在子线程中操作UI

    不管是android ,还是 ios ,请不要在子线程中操作UI,有时有些崩溃,从报错上看不出什么原因,就有可能是子线程操作了UI:切记,切记! 请放在主线程例: activity.runOnUiTh ...

随机推荐

  1. shell中的cat和文件分界符(<<EOF) (转)

    原文地址: http://blog.csdn.net/mosesmo1989/article/details/51123257 在shell中,文件分界符(通常写成EOF,你也可以写成FOE或者其他任 ...

  2. 什么是DQL、DML、DDL、DCL

    SQL(Structure Query Language)语言是数据库的核心语言. SQL的发展是从1974年开始的,其发展过程如下: 1974年-----由Boyce和Chamberlin提出,当时 ...

  3. .net中session的使用

    什么是Session? Session即会话,是指一个用户在一段时间内对某一个站点的一次访问. Session对象在.NET中对应HttpSessionState类,表示"会话状态" ...

  4. [BZOJ4196][NOI2015]软件包管理器(树链剖分)

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 2166  Solved: 1253[Submit][Sta ...

  5. 【树形DP】BZOJ1040-[ZJOI2008]骑士

    [题目大意] 有n个骑士,给出他们的能力值和最痛恨的一位骑士.选出一个骑士军团,使得军团内没有矛盾的两人(不存在一个骑士与他最痛恨的人一同被选入骑士军团的情况),并且,使得这支骑士军团最具有战斗力,求 ...

  6. PHP -- 模拟测试上传文件

    FROM :http://web.itivy.com/article-740-1.html QQ上传文件为什么那么快? “QQ上传大文件/QQ群发送大文件时,可以在极短的时间内完成”是如何做到的. 有 ...

  7. HDU 5301 Buildings 数学

    Buildings 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5301 Description Your current task is to m ...

  8. 动软代码生成器连接Oracle 11g

      首先要说明的是:如果你连接的是远程的Oracle服务器,你本地机器必须装Oracle客户端,然后 用sqldeveloper 先建立一个连接. 然后你才能用.NET动软代码生成器连接到数据库. 因 ...

  9. NFC TI TRF7970A Breakout Board for BusPirate or other HW

    http://dangerousprototypes.com/forum/viewtopic.php?f=19&t=3187 Just a news about a new Hardware ...

  10. servlet匹配路径时/和/*的区别(转)

    本文转自https://blog.csdn.net/rongxiang111/article/details/53008829 一.<url-pattern>/</url-patte ...