企业包_版本检查更新_定时返回结果
来源:互联网 发布:淘宝网男士大头皮鞋 编辑:程序博客网 时间:2024/05/01 09:27
技术难点:
1、在10s,访问服务器上的plist文件,NSDictionary(contentsOfURL)这个方法,请求时间长,且阻断当前的UI主线程,progressHUD加载不出来,所以考虑把这个方法放到另一个线程,这就要用到异步。
2、定时这个问题,performanselector这个方法已经禁用了,所以要用nstimer,
3、GCD能实现,progressHUD检测后回到主线程,但没有cancel的方法,dispatch_relase已经禁用,所以考虑NSoperation 这个可以cancel,但是没办法回到主线程,经学习后,发现NSOperationQueue.mainQueue().addOperationWithBlock,这就是回到主线程的方法,完美解决
4、另外附上一个大拿的博文,NSoperation比GCD更提倡使用,谢谢。
https://blog.cnbluebox.com/blog/2014/07/01/cocoashen-ru-xue-xi-nsoperationqueuehe-nsoperationyuan-li-he-shi-yong/
1、设访问plist文件的operation为全局变量。
var oper:NSBlockOperation!
2、编写版本检查更新的方法和定时取消检查更新的方法
func updateApp(){
self.showprogressHUD()
let que =NSOperationQueue()
NSTimer.scheduledTimerWithTimeInterval(1000, target:self, selector: "gettingNotification", userInfo:nil, repeats: false)
self.oper =NSBlockOperation{() -> Voidin
let dict =NSDictionary(contentsOfURL: NSURL(string: "\(UPDATEURL)/dfdf.plist")!)
print("\(dict)")
NSOperationQueue.mainQueue().addOperationWithBlock({ () ->Void in
if (dict !=nil){
let list = dict?.objectForKey("items")as! Array<AnyObject>
let dict2 = list[0]
let dict3 = dict2.objectForKey("metadata")
let newVersion = dict3?.objectForKey("bundle-version")as! String
let myVersion =NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"]as! String
self.removeLoadingView()
if(newVersion != myVersion){
let alertView =UIAlertView(title: "提示", message:"发现新版本", delegate:self, cancelButtonTitle: "确认")
alertView.tag =12001
alertView.show()
}else{
UIAlertView(title:"提示", message:"您已经是最新版", delegate:self, cancelButtonTitle: "确认").show()
}
}else{
self.removeprogressHUD()
}
})
}
que.addOperation(self.oper)
}
func gettingNotification(){
self.oper.cancel()
self.removeprogressHUD()
}
- 企业包_版本检查更新_定时返回结果
- 去掉quartz中的定时检查版本更新
- 多线程下载更新版本_
- _STL使用技巧_(不定时更新)
- Python 返回函数_闭包_装饰器
- 热更新_生成版本比较文本
- symbian 检查系统版本 完整(=_=)
- 一些实用的小技术,不定时更新^_^
- Vivado_MicroBlaze_问题及解决方法_汇总(不定时更新)
- Delphi7企业原版_史上最经典的delphi 版本
- 微信支付(java版本)_支付结果通知
- 微信支付(java版本)_支付结果通知
- 日记_教训_更新系统_注意照片、电话、程序、记录的文字、一遍一遍仔细检查
- 单片机_时钟定时
- ios检查版本更新
- ios检查版本更新
- 版本更新检查
- app 检查版本更新
- Openwrt修改flash大小
- 浅谈一个人是否适合学iOS
- 软件测试思想者(Software Testing - Thinker)博客启程了!
- Android Studio 更新 Android 6.0 之后无法找到 org.apache.http 包的问题
- Ext全选框
- 企业包_版本检查更新_定时返回结果
- 基于ndk jni技术实现串口收发的方法
- 使用python写神经网络模型之分类器
- uiwebview保存图片
- VMware网络配置笔记
- ubuntu16.04安装tomcat8.0.36
- Jquery删除table里面checkbox选中的多个行
- HTTP报文
- SQL Server 2012 Merge关键字