版本更新被拒绝解决方案

总结:由于苹果有自己的自动更新功能(当然你也可以不打开,可配置),所以以前通过比对版本号更新的那一套就算废了。为了解决,我们可以在服务端配置开关,这样,在审核的时候关闭,上线后打开。

那么什么时候才需要出现弹出框呢?

美味C端是这样处理的:

1.比对上次出现更新弹出框出现的时间,如果两次打开时间相距小于设定的时间,则不显示弹出框。

2.访问URLhttps://itunes.apple.com/us/lookup?id=979857479 获得一些跟APP有关的信息。

3.通过bundleId确认是此APP。

4.存在版本号并且系统当前的版本大于等于最小可支持的版本。

5.比较当前的版本号和appstore的版本号。如果一样则返回。

6.访问我们自己的服务器http://9now.cn/User/Version/index?VerCode=4.0.21&inhouse=0,查看是否需要更新,需要则显示弹出框。

7.弹出框有三种,下载,忽略此版本,稍后提醒我。

- (void)checkVersion{

    if (![selfshouldCheckForNewVersion]) {

        return;

    }

    BOOL inHouse =isInHouse;

    BOOL inAppStore =isAppStore;

    if (inHouse) {

        NSURL *URL = [NSURLURLWithString:INHOUSE_remoteVersionsPlistURLHTTPS];

        NSURLRequest *request = [NSURLRequestrequestWithURL:URL];

        

        NSURLSession *session = [NSURLSessionsharedSession];

        NSURLSessionDataTask *task = [sessiondataTaskWithRequest:request

                                                completionHandler:

                                      ^(NSData *data,NSURLResponse *response, NSError *error) {

                                          if(!data){

                                              return ;

                                          }

                                          NSPropertyListFormat format;

                                          NSDictionary *plistVersions = [NSPropertyListSerializationpropertyListWithData:data options:NSPropertyListImmutableformat:&format error:&error];

                                          //获取版本更新信息

                                          NSString *releaseNotes =nil;

                                          NSString *latestVersion =nil;

                                          if (plistVersions[@"releaseNotes"]) {

                                              releaseNotes = plistVersions[@"releaseNotes"];

                                          }

                                          if (plistVersions[@"version"]) {

                                              latestVersion = plistVersions[@"version"];

                                          }

                                          

                                          if (latestVersion){

                                              self.versionDic =@{latestVersion: releaseNotes ?:@""};

                                              [selfcheckForceUpgradeVersion];

                                          }

                                      }];

        [task resume];

    }elseif(inAppStore){

        //get country

        NSString *applicationBundleID = [[NSBundlemainBundle] bundleIdentifier];

        NSString *appStoreCountry = [(NSLocale *)[NSLocalecurrentLocale] objectForKey:NSLocaleCountryCode];

        if ([appStoreCountryisEqualToString:@"150"]){

            appStoreCountry = @"eu";

        }

        elseif ([[appStoreCountry stringByReplacingOccurrencesOfString:@"[A-Za-z]{2}"withString:@""options:NSRegularExpressionSearchrange:NSMakeRange(0,2)] length])

        {

            appStoreCountry = @"us";

        }

        

        //first check iTunes

        NSString *iTunesServiceURL = [NSStringstringWithFormat:iVersionAppLookupURLFormat, appStoreCountry];

        if (self.appStoreID){

            iTunesServiceURL = [iTunesServiceURL stringByAppendingFormat:@"?id=%@",@(self.appStoreID)];

        }else{

            iTunesServiceURL = [iTunesServiceURL stringByAppendingFormat:@"?bundleId=%@", applicationBundleID];

        }

        

        NSURL *URL = [NSURLURLWithString:iTunesServiceURL];

        NSURLRequest *request = [NSURLRequestrequestWithURL:URL];

        

        NSURLSession *session = [NSURLSessionsharedSession];

        NSURLSessionDataTask *task = [sessiondataTaskWithRequest:request

                                                completionHandler:

                                      ^(NSData *data,NSURLResponse *response, NSError *error) {

                                          //in case error is garbage...

                                          if (!data) {

                                              return ;

                                          }

                                          

                                          error = nil;

                                          id json =nil;

                                          if ([NSJSONSerializationclass]){

                                              json = [[NSJSONSerializationJSONObjectWithData:data options:(NSJSONReadingOptions)0error:&error][@"results"]lastObject];

                                          }else{

                                              //convert to string

                                              json = [[NSStringalloc] initWithData:dataencoding:NSUTF8StringEncoding];

                                          }

                                          

                                          if (!error){

                                              //check bundle ID matches

                                              NSString *bundleID = json[@"bundleId"];

                                              if (bundleID){

                                                  if ([bundleID isEqualToString:applicationBundleID]){

                                                     //get supported OS version

                                                     NSString *systemVersion = [UIDevicecurrentDevice].systemVersion;

                                                      

                                                     NSString *minimumSupportedOSVersion = json[@"minimumOsVersion"];

                                                     //get version details

                                                     NSString *releaseNotes = json[@"releaseNotes"];

                                                     NSString *latestVersion = json[@"version"];

                                                     BOOL osVersionSupported = ([systemVersioncompare:minimumSupportedOSVersionoptions:NSNumericSearch] !=NSOrderedAscending);

                                                     if (latestVersion && osVersionSupported)

                                                      {

                                                         self.versionDic =@{latestVersion: releaseNotes ?:@""};

                                                          [selfcheckForceUpgradeVersion];

                                                      }

                                                  }

                                              }

                                          }

                                      }];

        [task resume];

    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值