NTPManager

public class NTPManager : NSObject

NTPサーバーとの同期に使用するクラス。

  • AppleのNTPサーバーのホスト( time.apple.com )。

    Declaration

    Swift

    public static let EXAMPLE_HOST_APPLE: String
  • intdashデフォルトのNTPサーバーのホスト( ntp.vm2m.jp )。

    Declaration

    Swift

    public static let DEFAULT_HOST: String
  • タイムアウトのデフォルト値(1秒)。

    Declaration

    Swift

    public static let DEFAULT_TIMEOUT: TimeInterval
  • リトライ回数のデフォルト値(20回)。

    Declaration

    Swift

    public static let DEFAULT_RETRY: Int
  • IPアドレスごとのリトライ回数のデフォルト値(5回)。

    Declaration

    Swift

    public static let DEFAULT_FASTEST_RETRY: Int
  • NTPサーバー時刻と Date() で取得できる時刻との時刻差。NTPサーバーと同期した時刻は、 <Date()で取得した値> + offset の形式で算出されます。

    Declaration

    Swift

    public private(set) var offset: TimeInterval
  • NTPManagerを生成します。NTPサーバーにはデフォルト値( ntp.vm2m.jp )が使用されます。

    Declaration

    Swift

    public override init()
  • NTPManagerを生成します。

    Declaration

    Swift

    public init(hostName: String)

    Parameters

    hostName

    ホスト名 ( 例: ntp.vm2m.jp )

  • NTPサーバーと同期します。

    Declaration

    Swift

    public func sync(retry: Int = DEFAULT_RETRY, fastestRetry: Int = DEFAULT_FASTEST_RETRY, timeout: TimeInterval = DEFAULT_TIMEOUT, completion: @escaping (_ offset: TimeInterval, _ error: Error?) -> ())

    Parameters

    retry

    最大リトライ回数

    fastestRetry

    IPアドレスごとのリトライ回数

    timeout

    タイムアウト時間

    completion

    処理終了時のコールバック

    offset

    Date() で取得できる時間とのオフセット

    error

    エラー情報