Latest 0.0.3
Homepage https://github.com/DarkDust/MHSNTP
License BSD
Platforms ios 7.0, osx 10.7, tvos 9.0, requires ARC
Dependencies CocoaAsyncSocket
Authors

MHSNTP – SNTP pod

This is a pod for easy SNTP client support in macOS, iOS and tvOS. It’s main
goals are:

  • RFC 4330 compliance.
  • As much covered by unit tests as possible.
  • Modern Objective-C syntax for good support of both Objective-C and Swift.

This pod does not alter the system’s clock. It merely provides easy access to
networked time for your apps.

Current limitations

  • Only unicast operation is supported at the moment.

Dependencies

This pod requires CocoaAsyncSocket
to handle the UDP communication.

Integration in your project

There are two ways to integrate this pod: as module or not. To integrate using
modules, add use_frameworks! to your Podfile. After this, you reference the
pod like this:

// Objective-C
@import MHSNTP;

// Swift
import MHSNTP

If you are not using modules, you need to import the umbrella header in
Objective-C:

#import <MHSNTP/MHSNTP>

When using the pod in Swift without modules, you need add #import <MHSNTP/MHSNTP>
to your bridging header. No import MHSNTP is needed in this case.

Usage

The most simple way to use this pod is to instantiate a MHSNTPManager
instance and add Apple’s NTP servers (there’s a convenience method for that).

Objective-C example:

// Store the instance in a property or global variable to keep it alive.
MHSNTPManager * sntp = [[MHSNTPManager alloc] init];
[sntp addAppleSNTPServers];

// After adding the servers, the manager automatically starts querying them.
// You can then fetch the corrected current time via:
NSDate * now = [sntp now];

// Or you can query the offset of the local clock for other time calculations:
NSTimeInterval offset = [sntp systemClockOffset];

Swift example:

let sntp = MHSNTPManager()
sntp.addAppleSNTPServers()

let now = sntp.now()
let offset = sntp.systemClockOffset()

Please note that querying the servers for the first time is not instantaneous.
So you may want to instantiate the manager as early as possible/necessary in
your app’s lifecycle so you hopefully have received responses by the time you
actually need to use the network time.

Latest podspec

{
    "name": "MHSNTP",
    "version": "0.0.3",
    "summary": "SNTP client library",
    "description": "Easy to use SNTP client library.",
    "homepage": "https://github.com/DarkDust/MHSNTP",
    "license": {
        "type": "BSD",
        "file": "LICENSE"
    },
    "authors": {
        "Marc Haisenko": "[email protected]"
    },
    "platforms": {
        "ios": "7.0",
        "osx": "10.7",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/DarkDust/MHSNTP.git",
        "tag": "0.0.3"
    },
    "source_files": "MHSNTP/*.{h,m}",
    "requires_arc": true,
    "dependencies": {
        "CocoaAsyncSocket": [
            "~> 7"
        ]
    }
}

Pin It on Pinterest

Share This