[英]iPhone iOS 4 addTimeInterval deprecated
I'm using addTimeInterval
for creating local notification but it seems that it is now deprecated (iOS 4). 我正在使用
addTimeInterval
创建本地通知,但现在似乎已弃用(iOS 4)。
My code: 我的代码:
localNotif.fireDate = [now addTimeInterval:timeInterval];
Xcode's warning: Xcode的警告:
'addTimeInterval:' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:27)
What should I use instead? 我应该怎么用呢? Thanks.
谢谢。
The method has been renamed to -dateByAddingTimeInterval:
. 该方法已重命名为
-dateByAddingTimeInterval:
localNotif.fireDate = [now dateByAddingTimeInterval:timeInterval];
In Swift 2.2: 在Swift 2.2中:
localNotif.fireDate = now.dateByAddingTimeInterval(timeInterval)
In Swift 3: 在Swift 3中:
localNotif.fireDate = now.addingTimeInterval(timeInterval)
// or simply
localNotif.fireDate = now + timeInterval
try that: 尝试:
NSDate *date = [NSDate date]; // current date
NSTimeInterval delta = 60 * 1; // one minute later
if ([date respondsToSelector:@selector(dateByAddingTimeInterval:)]) {
date = [date dateByAddingTimeInterval:delta];
}
else {
date = [date addTimeInterval:delta];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.