스토리지

앱 업데이트를 위한 버전 체크 본문

개발일지

앱 업데이트를 위한 버전 체크

ljw4104 2021. 8. 1. 17:09

마켓 API나 이런게 있을 줄 알았는데 어림도 없다.

답은 HTML 파싱 하나 뿐인 것 같다.

서버로 받아오는 법도 있지만 귀찮다.


준비물

  1. 어플 주소
  2. HtmlAgilityPack

Html Agility Pack은 아래의 주소에서 받을 수 있다.

https://html-agility-pack.net/

 

Html Agility pack | Html Agility Pack

Html Agility Pack is FREE and always will be. However, last year alone, we spent over 3000 hours maintaining our free projects! We need resources to keep developing our open-source projects. We highly appreciate any contribution!

html-agility-pack.net

다운로드 뒤, Assets 폴더 아래의 아무데나 넣으면 된다.

저같은 경우에는 Assets폴더 아래의 ThirdParty라는 폴더에 넣어주었습니다.

HTML 파싱을 편하게 해주는 라이브러리이다.


코드

2개의 클래스를 작성해야 한다.

 

UnsafeSecurityPolicy.cs

using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;

public class UnsafeSecurityPolicy
{
    public static bool Validator(
        object sender,
        X509Certificate certificate,
        X509Chain chain,
        SslPolicyErrors policyErrors)
    {
        Debug.Log("Validation successful!");
        return true;
    }

    public static void Instate()
    {
        ServicePointManager.ServerCertificateValidationCallback = Validator;
    }
}

이게 아직 무슨 일을 하는 클래스인지 모르겠다.. 하지만 없으면 다음과 같은 에러를 발생시킨다.

TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a

 

 

VersionChecker.cs

using System.Text.RegularExpressions;
using UnityEngine;
using HtmlAgilityPack;


public class UpdateChecker : MonoBehaviour
{
    private HtmlWeb web;
    private HtmlDocument doc;
    private string marketVersion;
    private const string url = "https://play.google.com/store/apps/details?id=com.DJS.InChoice";
    public bool CheckVersion()
    {
        UnsafeSecurityPolicy.Instate();

        this.web = new HtmlWeb();
        this.doc = web.Load(url);

        foreach(HtmlNode node in doc.DocumentNode.SelectNodes("//span[@class='htlgb']"))
        {
            this.marketVersion = node.InnerText.Trim();
            if (marketVersion != null)
            {
                if (Regex.IsMatch(this.marketVersion, @"^\d{1}\.\d{1}\.\d{1}$"))
                {
                    string myVer = Application.version;
                    string marketVer = this.marketVersion;

                    if(myVer != marketVer)
                    {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}

MonoBehaviour을 상속 안받아도 되지만 불러오기 편하기 위해서 그냥 상속시켰다...

예제를 돌려보고 다중 apk? 때문에 마켓에 버전이 표시되지 않는다,..

실제로 프로젝트에 적용시킨 코드이다.

if (this.updateChecker.CheckVersion())
{
    this.ChangeScene("Logo");
}
else
{
    this.updatePopup.SetActive(true);
}

updateChecker의 CheckVersion()함수는 마켓의 버전과 똑같을 때, true를 return한다.

 

다음의 게시글을 참고하면서 적었습니다.

https://blog.naver.com/path3rz/222037362991

 

[유니티(Unity)] 게임 업데이트 알림 기능 수정

※이 글은 모바일에 최적화 되어있습니다. 안녕하세요. 전 게시글에서 게임 업데이트 기능 소스코드를 공개...

blog.naver.com

 


 

아무리봐도 마켓을 통한 버전 확인은 포기해야 될 것 같다.

마켓 파싱은 막힌거같다

다른 방법을 찾아봐야된다...

 

빌드할 때마다, 서버로 버전을 전송한다던가?

- 서버에 전송한다 쳐도 마켓에 해당버전을 반영하는데 시간이 걸릴거라 애매하다. 이런 방식으로 만들면 만약 새 버전이 검토중일 때는 계속 버전이 맞지않아 게임자체가 불가능해진다.

'개발일지' 카테고리의 다른 글

Unity Learn 보고 만든 게임  (0) 2021.09.13
2D 플랫포머 게임 만들기 1일차  (0) 2021.09.11
젠킨스 전체 콘솔출력  (0) 2021.08.01
Jenkins 빌드 오류 - 1트라이  (0) 2021.07.31
Jenkins로 유니티 자동 빌드하기  (0) 2021.07.31
Comments