본문으로 바로가기

+ (BOOL)needsUpdate

{

    NSDictionary* infoDictionary = [[NSBundle mainBundleinfoDictionary];

    NSString* appID = infoDictionary[@"CFBundleIdentifier"];

    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];

    NSData* data = [NSData dataWithContentsOfURL:url];

    NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

    

    BOOL result = NO;

    

    if ([lookup[@"resultCount"integerValue] == 1){

        NSString* appStoreVersion = lookup[@"results"][0][@"version"];

        NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];


        NSArray *versionArray = [currentVersion componentsSeparatedByString:@"."];

        NSArray *appStoreArray = [appStoreVersion componentsSeparatedByString:@"."];

        

        for (int i=0; i<appStoreArray.count; i++) {

            

            int bundleStat = [versionArray[i] intValue];

            int serverStat = [appStoreArray[i] intValue];

            

            if (bundleStat == serverStat) {

                result = NO;

                continue;

                

            } else if (bundleStat > serverStat) {

                result = NO;

                break;

                

            } else {

                result = YES;

                break;

            }

        }

    }

    

    return result;

}



출처: http://you9010.tistory.com/137 [uujing의 블로그]