This commit is contained in:
Vladimir Dubovik
2025-06-13 11:59:16 +03:00
parent 2204bb9fe0
commit 5abafda21b
152 changed files with 9783 additions and 69 deletions

View File

@ -0,0 +1,26 @@
//
// AppDelegate.swift
// NTPExample
//
// Created by Michael Sanders on 7/9/16.
// Copyright © 2016 Instacart. All rights reserved.
//
import UIKit
import TrueTime
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
TrueTimeClient.sharedInstance.start()
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = .white
window?.makeKeyAndVisible()
window?.rootViewController = ExampleViewController()
return true
}
}

View File

@ -0,0 +1,93 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@ -0,0 +1,29 @@
//
// Bridging.m
// TrueTime-iOS
//
// Created by Michael Sanders on 1/2/18.
// Copyright © 2018 Instacart. All rights reserved.
//
@import TrueTime;
@interface Bridging : NSObject
@end
@implementation Bridging
- (void)testBridging {
TrueTimeClient *client = [TrueTimeClient sharedInstance];
[client startWithPool:@[(id)[NSURL URLWithString:@"time.apple.com"]] port: 123];
NSDate *now = [[client referenceTime] now];
NSLog(@"True time: %@", now);
[client fetchIfNeededWithSuccess:^(NTPReferenceTime *referenceTime) {
NSLog(@"True time: %@", [referenceTime now]);
} failure:^(NSError *error) {
NSLog(@"Error! %@", error);
}];
}
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@ -0,0 +1,98 @@
//
// ViewController.swift
// TrueTime
//
// Created by Michael Sanders on 10/26/16.
// Copyright © 2016 Instacart. All rights reserved.
//
import UIKit
import TrueTime
final class ExampleViewController: UIViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
NotificationCenter.default.addObserver(
self,
selector: #selector(startTimer),
name: UIApplication.didBecomeActiveNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(cancelTimer),
name: UIApplication.willResignActiveNotification,
object: nil
)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit {
NotificationCenter.default.removeObserver(self)
}
override func viewDidLoad() {
super.viewDidLoad()
label.frame = view.bounds.insetBy(dx: 15, dy: 15)
label.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(label)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
refresh()
startTimer()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
cancelTimer()
}
fileprivate var referenceTime: ReferenceTime?
fileprivate var timer: Timer?
fileprivate lazy var label: UILabel = {
let label = UILabel()
label.textColor = .black
label.textAlignment = .center
label.font = .systemFont(ofSize: 14)
label.numberOfLines = 0
return label
}()
}
private extension ExampleViewController {
@objc func startTimer() {
timer = .scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
self?.tick()
}
}
@objc func cancelTimer() {
timer?.invalidate()
timer = nil
}
func tick() {
if let referenceTime = referenceTime {
let trueTime = referenceTime.now()
label.text = "\(trueTime)\n\n\(referenceTime)"
}
}
func refresh() {
TrueTimeClient.sharedInstance.fetchIfNeeded { result in
switch result {
case let .success(referenceTime):
self.referenceTime = referenceTime
print("Got network time! \(referenceTime)")
case let .failure(error):
print("Error! \(error)")
}
}
}
}