友盟更新(自定义)

本文介绍了一个iOS应用如何在启动时检查是否有新版本可用,并通过友盟统计服务进行应用内更新提示的实现过程。包括AppDelegate配置、启动时统计设置及版本检查逻辑、更新提示对话框展示等关键步骤。

@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];

    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值