自己整理的ios app实现自动升级
2014-06-11 14:09
381 查看
主要是写cordova插件
<!---------------------------CheckUpdate.h文件----------------------------------------->
#import <Cordova/CDVPlugin.h>
@interface CheckUpdate : CDVPlugin{
NSString *trackViewUrl;
}
@property (nonatomic,retain) NSString *trackViewUrl;
- (void)checkUpdate:(NSMutableArray*)arguments withDict:(NSDictionary*)options;
@end
<!---------------------------CheckUpdate.m文件----------------------------------------->
#import "CheckUpdate.h"
@implementation CheckUpdate
@synthesize trackViewUrl;
- (void)checkUpdate:(NSMutableArray*)arguments withDict:(NSDictionary*)options{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];
NSError *error;
NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=739680648"];
NSURLRequest *request= [NSURLRequest requestWithURL:url];
NSData *response=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSArray *res= [dict objectForKey:@"results"];
if([res count]){
NSDictionary *resDict= [res objectAtIndex:0];
NSString *newVersion = [resDict objectForKey:@"version"];
self.trackViewUrl=[resDict objectForKey:@"trackViewUrl"];
if([nowVersion isEqualToString:newVersion]==NO)
{
NSString *message=[[NSString alloc] initWithFormat:@"当前版本为%@,最新版本为%@", nowVersion, newVersion];
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"检测版本更新" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新", nil ];
[alert show];
[alert release];
}else{
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"检测版本更新" message:@"已经是最新版本了" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1){
NSURL *url= [NSURL URLWithString: self.trackViewUrl];
[[UIApplication sharedApplication] openURL:url];
[url release];
}
}
@end
<!---------------------------CheckUpdate.h文件----------------------------------------->
#import <Cordova/CDVPlugin.h>
@interface CheckUpdate : CDVPlugin{
NSString *trackViewUrl;
}
@property (nonatomic,retain) NSString *trackViewUrl;
- (void)checkUpdate:(NSMutableArray*)arguments withDict:(NSDictionary*)options;
@end
<!---------------------------CheckUpdate.m文件----------------------------------------->
#import "CheckUpdate.h"
@implementation CheckUpdate
@synthesize trackViewUrl;
- (void)checkUpdate:(NSMutableArray*)arguments withDict:(NSDictionary*)options{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *nowVersion = [infoDict objectForKey:@"CFBundleVersion"];
NSError *error;
NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=739680648"];
NSURLRequest *request= [NSURLRequest requestWithURL:url];
NSData *response=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *dict= [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSArray *res= [dict objectForKey:@"results"];
if([res count]){
NSDictionary *resDict= [res objectAtIndex:0];
NSString *newVersion = [resDict objectForKey:@"version"];
self.trackViewUrl=[resDict objectForKey:@"trackViewUrl"];
if([nowVersion isEqualToString:newVersion]==NO)
{
NSString *message=[[NSString alloc] initWithFormat:@"当前版本为%@,最新版本为%@", nowVersion, newVersion];
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"检测版本更新" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"更新", nil ];
[alert show];
[alert release];
}else{
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"检测版本更新" message:@"已经是最新版本了" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1){
NSURL *url= [NSURL URLWithString: self.trackViewUrl];
[[UIApplication sharedApplication] openURL:url];
[url release];
}
}
@end
相关文章推荐
- 自己整理的ios app实现自动升级
- 自己整理的ios app实现自动升级
- android app升级(下载)完毕后自动弹出安装界面的实现
- iOS开发app自动更新的实现
- ionic 实现自动升级APP
- iOS逆向工程(手动HOOK自己编写的APP)- 学习整理
- iOS开发之APP升级的实现
- ios开发之APP升级的实现
- app实现自动升级
- MVP+多线程+断电续传 实现app在线升级库 (手把手教你打造自己的lib)
- ios开发之APP检查升级的实现
- 让我们自己的Android程序可以自动后台升级的实现(需Root权限)
- 自己实现app的版本升级
- android 实现app内部检测最新版本 自动升级到最新版本
- iOS 托管App到FIR 实现软件内升级
- IOS开发中如何实现自动检测更新APP
- iOS 开发笔记 - 开发中如何实现自动检测更新APP
- MVP+多线程+断点续传 实现app在线升级库 (手把手教你打造自己的lib)
- iOS 基础篇14- APP升级的实现
- iOS 开发笔记 - 开发中如何实现自动检测更新APP