项目地址:https://github.com/jbenet/ios-ntp
NTP 维基百科:http://en.wikipedia.org/wiki/Network_Time_Protocol
准备工作
git clone 项目 ios-ntp
https://github.com/jbenet/ios-ntp.git
git clone 项目 CocoaAsyncSocket
https://github.com/robbiehanson/CocoaAsyncSocket.git
1、添加frameworks
解压缩ios-ntp/release/ios-ntp.tar.gz,得到ios-ntp.framework文件夹,拷贝到项目下
Targets -> Build Phases -> Link Binary With Libraries,点击+,弹出framwork列表,点击add others...按钮,选择ios-ntp.framework
添加CFNetwork.framework
2、添加CocoaAsyncSocket依赖文件
添加文件,选择CocoaAsyncSocket/RunLoop目录下AsyncUdpSocket.h和AsyncUdpSocket.m两个文件
代码示例:
NSDate *networkTime = [NSDate networkDate]; networkTimeLable.text = [NSString stringWithFormat:@"%@", networkTime];