Objective c 使用NTP/Timeserver的UILocalnotification
我的应用程序需要触发几个UILocalNotification,但是这些通知取决于系统时间,我无法让它们使用示例中的NTP 该脚本可以工作,但无法修复UILocalnotifications时间 例如,这是我的通知脚本(更新来自Martin R.) 通知应在15.58发出,实时时间为15.00,但用户希望在15.01显示通知,因此他将设备时间“黑”到15.57,以便设备在一分钟内显示通知。 既然我的应用程序需要工作,我该如何防止这种情况。 我尝试将NTP添加到我的项目中,它加载但不起作用:Objective c 使用NTP/Timeserver的UILocalnotification,objective-c,ios6,uilocalnotification,Objective C,Ios6,Uilocalnotification,我的应用程序需要触发几个UILocalNotification,但是这些通知取决于系统时间,我无法让它们使用示例中的NTP 该脚本可以工作,但无法修复UILocalnotifications时间 例如,这是我的通知脚本(更新来自Martin R.) 通知应在15.58发出,实时时间为15.00,但用户希望在15.01显示通知,因此他将设备时间“黑”到15.57,以便设备在一分钟内显示通知。 既然我的应用程序需要工作,我该如何防止这种情况。 我尝试将NTP添加到我的项目中,它加载但不起作用: #i
#import "AsyncUdpSocket.h"
#import "lib/ios-ntp.h"
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
[NSDate networkDate];
}
您可以计算设备日期和网络日期之间的差异:
NSTimeInterval *timeAdjustment = [[NSDate date] timeIntervalSinceDate:[NSDate networkDate]]
并相应调整通知的火灾日期:
fireDate = [fireDate dateByAddingTimeInterval:timeAdjustment];
AFAIK通知是根据系统时间设置的。您对NSDate所做的更改将仅在您的application@SuhailPatel我不知道,有没有一种方法可以将它应用到我的通知中?我现在尝试了这个方法,但是它没有在正确的时间发出通知。请查看我的更新代码和您的建议。谢谢。@user2460028:通知何时发出?可能还会显示
timeAdjustment
、fireDate
(调整前后)和报警的NSLog输出。不,通知根本没有运行,我尝试了NSLogtimeAdjustment,fireDate
,但应用程序不会运行,然后它会给我以下错误:传递'NSTimeInterval'(也称为'double')对于不兼容类型为“NSString*”的参数,
@user246028:NSLog(@“timeAdjustment=%f”,timeAdjustment)
,NSLog(@“fireDate=%@”,fireDate)
和NSLog(@“alarm=%@”,alarm)
应该可以工作。@user246028:如果不调整时间,通知可以工作吗?
fireDate = [fireDate dateByAddingTimeInterval:timeAdjustment];