835 バイト追加,
2020年3月5日 (木) 03:14 ソフトウェアのアップデートなどアプリ自身を再起動したいときがある。
== 実装 ==
AppDelegateクラスのWillTerminateメソッドに再起動する処理を記述する。
この状態でRestartRequestedフラグにtrueを設定してアプリを終了すれば再起動になる。
<source lang="csharp">
public override void WillTerminate (NSNotification notification)
{
if (RestartRequested)
{
NSWorkspace.SharedWorkspace.LaunchApp (NSBundle.MainBundle.BundleIdentifier,
NSWorkspaceLaunchOptions.NewInstance | NSWorkspaceLaunchOptions.Async,
NSAppleEventDescriptor.NullDescriptor,
IntPtr.Zero);
}
}
</source>
[[category: Xamarin.Mac]]