LoginSignup
0
0

More than 5 years have passed since last update.

WindowsでAdHoc(ipaファイル)の有効期限を調べる方法

Posted at

今ってTestFlightが主流でAdHocってあんまり使われてないんでしょうかね?

年一でAdHocが期限切れを起こすため、AdHocファイル(ipaファイル)の書き出し直し作業を手動でやっている(&やってもらっている)のですが、ちゃんと期限が伸びたipaファイルになっているかを確認する手段が判らなかったので適当に作ってみました。

コード

仕事のメイン機がWindowsという事もあってC#で実装。

hoge
        internal static string GetExpirationDate(string path)
        {
            try
            {
                using (var archive = ZipFile.OpenRead(path))
                {
                    foreach (var ent in archive.Entries)
                    {
                        if (string.Compare("embedded.mobileprovision", ent.Name, true) == 0)
                        {
                            using (var stream = ent.Open())
                            {
                                var buffer = new byte[ent.Length];
                                stream.Read(buffer, 0, (int)ent.Length);

                                var cms = new SignedCms();
                                cms.Decode(buffer);
                                var xml = Encoding.UTF8.GetString(cms.ContentInfo.Content);
                                var m = Regex.Match(xml, @"<key>ExpirationDate</key>.*?<date>(.*?)</date>", RegexOptions.Singleline);
                                if (m.Success)
                                {
                                    DateTime res;
                                    if (DateTime.TryParse(m.Groups[1].ToString(), out res))
                                    {
                                        return res.ToString();
                                    }
                                    return m.Groups[1].ToString();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception) { }

            return "??";
        }

参照にSystem.IO.CompressionSystem.IO.Compression.FileSystemSystem.Security辺りを突っ込まないと使えないかも。
ZIP(=ipa)の中のembedded.mobileprovisionファイルを解凍してCMSでデコードして、ExpirationDateキーの値を拾ってきているだけです。

#そもそもアプリ数が増えてくるとAdHocを作りなおすのが面倒くさいのですが、その辺皆さんどうされていますか?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0