「Xamarin.AndroidでUUIDを生成取得する」の版間の差分

提供:MonoBook
編集の要約なし
編集の要約なし
 
3行目: 3行目:
[[リセマラ]]対応[[ゲーム]]などを作るときはこれ。
[[リセマラ]]対応[[ゲーム]]などを作るときはこれ。


<source>
<source lang="csharp">
    public class Installation
public class Installation
{
    public static string _uuid;
    public const string INSTALLATION = "INSTALLATION";
 
    public static string GetUUID(Context context)
     {
     {
         public static string _uuid;
         if (_uuid == null)  
        public const string INSTALLATION = "INSTALLATION";
 
        public static string GetUUID(Context context)
         {
         {
             if (_uuid == null)  
            var installationFilePath = Path.Combine(context.FilesDir.AbsolutePath, INSTALLATION);
             if (!File.Exists(installationFilePath))
             {
             {
                 var installationFilePath = Path.Combine(context.FilesDir.AbsolutePath, INSTALLATION);
                 _uuid = System.Guid.NewGuid().ToString();
                if (!File.Exists(installationFilePath))
                File.WriteAllText(installationFilePath, _uuid);
                {
                    _uuid = System.Guid.NewGuid().ToString();
                    File.WriteAllText(installationFilePath, _uuid);
                }
                _uuid = File.ReadAllText(installationFilePath);
             }
             }
             return _uuid;
             _uuid = File.ReadAllText(installationFilePath);
         }
         }
        return _uuid;
     }
     }
}
</source>
</source>



2024年3月25日 (月) 05:33時点における最新版

アプリ固有のIDを生成して保存しておく。 この方法だと再インストールするとIDは変わる。 リセマラ対応ゲームなどを作るときはこれ。

public class Installation
{
    public static string _uuid;
    public const string INSTALLATION = "INSTALLATION";

    public static string GetUUID(Context context)
    {
        if (_uuid == null) 
        {
            var installationFilePath = Path.Combine(context.FilesDir.AbsolutePath, INSTALLATION);
            if (!File.Exists(installationFilePath))
            {
                _uuid = System.Guid.NewGuid().ToString();
                File.WriteAllText(installationFilePath, _uuid);
            }
            _uuid = File.ReadAllText(installationFilePath);
        }
        return _uuid;
    }
}

関連項目[編集 | ソースを編集]