@interface AppDelegate : UIResponder <UIApplicationDelegate,UIScrollViewDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, copy) NSString *iNewVersionPath;//新版本号
@property (nonatomic, assign)BOOL iIsNewVersion;//是否是新版本
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//友盟统计,BATCH(启动时发送)和SEND_INTERVAL(按间隔发送)
[MobClick startWithAppkey:UMENAPPKEY reportPolicy:BATCH channelId:nil];
//检查更新
//兼容xcode4以上,所以需要设置version,否则在updateMethod中返回的appInfo中当前版本号为build的版本号;Tatgets->General->Identity->Build
//Xcode有两个版本号,一个是Version
,另一个是Build
,对应于Info.plist的字段名分别为CFBundleShortVersionString
,CFBundleVersion
NSString *tVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
[MobClick setAppVersion:tVersion];
[MobClick checkUpdateWithDelegate:self selector:@selector(updateMethod:)];
}
- (void)updateMethod:(NSDictionary *)appInfo {
NSLog(@"update info %@",appInfo);
if([[appInfo objectForKey:@"update"] isEqualToString:@"YES"]==YES)
{
NSString *newVersion = [[NSString alloc]initWithString:[appInfo objectForKey:@"version"]];
_iNewVersionPath = [[NSString alloc]initWithString:[appInfo objectForKey:@"path"]];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"有新版本V%@",newVersion] message:[NSString stringWithString:[appInfo objectForKey:@"update_log"]] delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles:@"更新", nil];
[alert show];
_iIsNewVersion = NO;
}
else
{
_iIsNewVersion = YES;
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==1)
{
NSURL *url = [NSURL URLWithString:_iNewVersionPath];
[[UIApplication sharedApplication]openURL:url];
}
}