티스토리 뷰

고객사에서 신규 업데이트가 있을 경우 앱 실행시 팝업창을 출력해달라고해서 만들어보았다.






-(void)verCheck{

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

    NSString *bundleIdentifier = [bundleInfo valueForKey:@"CFBundleIdentifier"];

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

    NSData *lookupResults = [NSData dataWithContentsOfURL:lookupURL];

    NSDictionary *jsonResults = [NSJSONSerialization JSONObjectWithData:lookupResults options:0 error:nil];

    

    NSUInteger resultCount = [[jsonResults objectForKey:@"resultCount"] integerValue];

    if (resultCount){

        NSDictionary *appDetails = [[jsonResults objectForKey:@"results"] firstObject];

        NSString *latestVersion = [appDetails objectForKey:@"version"];

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

        NSLog(@"latestVersion====%@",latestVersion);

        NSLog(@"currentVersion====%@",currentVersion);

        

//앱스토어에 올라간 버전과 빌드버전이 다를경우 팝업을 출력한다.

        if(latestVersion!=currentVersion){

            NSLog(@"업데이트가 필요함");

            

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"앱 업데이트 안내"

                                                                               message:@"앱이 업데이트 되었습니다. \n최신버전으로 업데이트 해주세요"

                                                                              delegate:self

                                                                     cancelButtonTitle:@"취소"    /* nil 로 지정할 경우 cancel button 없음 */

                                                                     otherButtonTitles:@"앱스토어로 이동", nil];

            [alert show];

        }

    }

    

}




//앱스토어로 이동 버튼 클릭시

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

{

    // OK 버튼을 눌렀을 때 버튼Index가 1로 들어감

    if (buttonIndex == 1) {

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://naver.com"]];

    }

    else {

        

    }

}


사용하땐 팝업 호출하는 부분이랑 앱스토어의 앱 주소만 변경해서 쓰면 된다.