应用在AppStore检测版本更新


// appstore的情况下,版本检查升级的处理



#define  kShiperAppID     @"AppStore中查看AppId"


#define  kURLLookup   @"http://itunes.apple.com/cn/lookup?id=%@"


#pragma mark - appStore检查更新
- (void)checkUpdate:(id)sender{

    __weak typeof(self) wself = self;
    [MBProgressHUD showHUDAddedTo:self.window animated:YES];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(){
        //        NSString *url = [NSString stringWithFormat:kURLLookup,@"423084029"];
        //        if ([self.type isEqualToString:@"shipper"]) {
        NSString *url = [NSString stringWithFormat:kURLLookup,kShiperAppID];
        //        }
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:url]];
        [request setHTTPMethod:@"GET"];
        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        NSDictionary *result = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];
        NSString *serverV  = @"";
        NSString *serVInfo = @"";
        do
        {
            if (!result){
                break;
            }
            id ary = result[@"results"];
            if (!ary || NO == [ary isKindOfClass:[NSArray class]]) {
                break;
            }
            if ([(NSArray*)ary count] <= 0) {
                break;
            }
            NSDictionary* dict = ary[0];
            if (!dict) {
                break;
            }
            serverV = [dict objectForKey:@"version"];
            serVInfo = [dict objectForKey:@"releaseNotes"];
        }while (NO);

        dispatch_async(dispatch_get_main_queue(), ^(){
            [MBProgressHUD hideAllHUDsForView:wself.window animated:YES];
            NSString* currver = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
            if ([currver length] == 0)
            {
                currver = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
            }
            if (serverV.length > 0 && NSOrderedDescending == [self verseionCompare:currver ver2compare:serverV]) {

                NSString* tipmsg   = [NSString stringWithFormat:@"发现新版:%@\r\n%@",serverV,serVInfo];

                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil
                                                               message:tipmsg
                                                              delegate:self
                                                     cancelButtonTitle:@"取消"
                                                     otherButtonTitles:@"更新",nil];
                [alert show];
            }else{//如果是最新版本则不提醒
                //                [self showMessageWith:@"您当前的版本已是最新版本"];
                //                NSString* tipmsg   = [NSString stringWithFormat:@"发现新版:%@\r\n%@",serverV,serVInfo];
                //
                //                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil
                //                                                               message:tipmsg
                //                                                              delegate:self
                //                                                     cancelButtonTitle:@"取消"
                //                                                     otherButtonTitles:@"更新",nil];
                //                [alert show];

            }
        });
    });
}
#pragma mark - AlertView Delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        NSLog(@"quxiao");
    }else{
        NSLog(@"gengxin");
        //                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@",@"423084029"]]];    //美团测试能用
        if ([kPublicChanel isEqualToString:@"appstore"]) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/app/id%@",kShiperAppID]]];
        }
        else
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.latestVersionPath]];
        }
    }
}
时间: 2024-08-10 21:29:31

应用在AppStore检测版本更新的相关文章

iOS 检测版本更新(02)

iOS 检测版本更新 如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bundle version中获取: [cpp] view plaincopy NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDic); NSString *appVersion = [infoDic

iOS 检测版本更新

iOS 检测版本更新 分类: IOS_XCODE 2013-07-19 16:52 18252人阅读 评论(5) 收藏 举报 如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bundle version中获取: [cpp] view plaincopy NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionar

iOS通过iTunes search检测版本更新,并提示用户更新

如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bundle version中获取: NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDic); NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion&

检测版本更新

如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bundle version中获取: [cpp] view plaincopy NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; ]; 这样就获取到当前运行的app的版本了 要获取当前app store上的最新的版本,有两种方法, 一.在某特定的服

安卓APP采用观察者模式实现检测版本更新

第一步:定义观察者 public interface CheckVersionObserver { /** * 在MainActivity里面检测版本更新成功 * @param mainEntity */ public void onCheckNewVerSuccInMain(MainEntity mainEntity); /** * 检测新版本失败 * @param errorCode * @param msg */ public void onCheckNewVerFail(int erro

iOS自动检测版本更新

虽然苹果官方是不允许应用自动检测更新,提示用户下载,因为苹果会提示你有多少个软件需要更新,但是有的时候提示用户一下有新版还是很有必要的. 首先说一下原理: 每个上架的苹果应用程序,都会有一个应用程序的ID,根据这个ID我们就可以获取到当前程序的最新版本号,然后和自己的版本号作比较,如果一样的话就是最新版,反之就不是新版,就可以提示用户来手动下载最新版的程序.因为有ID所以就可以定位到这个APP,点击下载即可. 源码: 一般建议检测更新的代码放到主页控制器里. 首先还要导入一个头文件用来打开App

iOS 检测版本更新处理

如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bundle version中获取: NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"]; 这样就获取

android检测版本更新

原理就是从服务器获取版本号和本得apk的版本号对比更新: //检查更新        Activity activity = this;        while(activity.getParent()!=null){            activity = activity.getParent();        }        new UpdateManager(activity, true).checkUpdate(); 下面是UpdateManager.java类: packag

iOS开发之Appstore篇——版本更新

1.版本更新方法 + (void)updateWithAPPID:(NSString *)appid back:(void (^)(NSString *, NSString *, NSString *, BOOL))back{ NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; __block NSString *currentVersion = infoDic[@"CFBundleShortVersionString&