zoukankan      html  css  js  c++  java
  • 关于提示版本升级~

    今天遇到了关于版本升级的问题,弹出提示框给用户提醒升级,一个版本只提醒一次

    http://www.jianshu.com/p/62a18e8ed92b   这个是原文,但是有错误 这里改动了一下加了些需求

     

    #define kAPP_URL [AppDelegate isLanguageEnglish]?@"http://itunes.apple.com/lookup?id=":@"http://itunes.apple.com/cn/lookup?id="

    #define kAppId  @"1111111111"//appID

     

    - (void)updateApp

    {

        NSError *error;

        

        NSString *urlStr = [NSString stringWithFormat:@"%@%@",kAPP_URL,kAppId];

        NSURL *url = [NSURL URLWithString:urlStr];

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

        

        NSDictionary *appInfoDict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:&error];

        

        if (error) {

            NSLog(@"%@", error.description);

            return;

        }

        

        NSArray *resultArray = [appInfoDict objectForKey:@"results"];

        

        if (![resultArray count]) {

            NSLog(@"error : resultArray == nil");

            return;

        }

        

        NSDictionary *infoDict = [resultArray objectAtIndex:0];

        //获取服务器上应用的最新版本号

        NSString *updateVersion = infoDict[@"version"];

        NSString *trackName = infoDict[@"trackName"];

        

        _trackViewUrl = infoDict[@"trackViewUrl"];

        

        //获取当前设备中应用的版本号

        NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

        NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

        

        NSArray<NSString*> *currentArray = [currentVersion componentsSeparatedByString:@"."];

        NSArray<NSString*> *updateArray = [updateVersion componentsSeparatedByString:@"."];

        

        NSMutableString *currentString = [NSMutableString string];

        for (NSString *str in currentArray) {

            NSString * tempstr = [NSString stringWithFormat:@"%03d",[str intValue]];

            [currentString appendString:tempstr];

        }

        

        NSMutableString *updateString = [NSMutableString string];

        for (NSString *str in updateArray) {

            NSString * tempstr = [NSString stringWithFormat:@"%03d",[str intValue]];//补全位数再比较大小

            [updateString appendString:tempstr];

        }

        if ([[NSUserDefaults standardUserDefaults]objectForKey:updateString]) {

            return;

        }else{

            [[NSUserDefaults standardUserDefaults]setObject:@0 forKey:updateString];//一个版本只提醒一次

        }

        

        //判断两个版本是否相同

        if ([currentString longLongValue] < [updateString longLongValue]) {

            NSString *titleStr = [NSString stringWithFormat:@"检查更新:%@", trackName];

            NSString *messageStr = [NSString stringWithFormat:@"发现新版本 %@ 是否更新 %@", updateVersion,infoDict[@"releaseNotes"]];//版本更新内容

            

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"升级", nil];

            

            alert.tag = [kAppId intValue];

            [alert show];

        }

    }

    //判断用户点击了哪一个按钮

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

    {

        if (alertView.tag == [kAppId intValue]) {

            if (buttonIndex == 1) { //打开app store上应用的详情页面

                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.trackViewUrl]];

            }

        }

    }

  • 相关阅读:
    Changing Icon File Of Push Button At Runtime In Oracle Forms 6i
    Set Font Properties On Mouse Hover Of Push Button And Text Items At Run time In Oracle Forms
    Change An Item Property Using Set_Item_Property In Oracle Forms
    Calling / Running a report in Oracle forms 10g / 11g
    Change Or Set Report Object Property At Run Time In Oracle Forms Using Set_Report_Object_Property Command
    Refresh / Updating a form screen in Oracle D2k Forms 6i
    Know How And When To Use System.Message_Level To Control Messages In Oracle Forms
    Perform Cut Copy Paste Operations Using Cut_Region Copy_Region Paste_Region Commands In Oracle Forms
    CHECKBOX_CHECKED built-in in Oracle D2k Forms
    Limiting To Select Only 5 Check Boxes Out Of Ten In Oracle Forms
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5859856.html
Copyright © 2011-2022 走看看