[IOS] Objective-C

[IOS] 앱스토어와 현재 디바이스와의 버전 비교 체크

최고관리자
2019.01.22 09:47 2,618 0

본문

앱스토어 버전을 체크하여 업데이트가 필요하면 ture 를 리턴해주는 방식이다.


http://itunes.apple.com/lookup 이 주소로 접근하여 스토어에서 앱의 정보를 못가져 오는 경우는

http://itunes.apple.com/kr/lookup  이와같이 kr을 추가해 줘야 한다. 


- (BOOL) needsUpdate {

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

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

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

NSData* data = [NSData dataWithContentsOfURL:url];

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

     

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

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

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

         

if (![appStoreVersion isEqualToString:currentVersion]) {

return YES;

}

}

return NO;

}

댓글목록 0

등록된 댓글이 없습니다.