Iñi*_*tia 34 iphone xcode nsdate ios4
我正在使用它addTimeInterval来创建本地通知,但它现在似乎已被弃用(iOS 4).
我的代码:
localNotif.fireDate = [now addTimeInterval:timeInterval];
Run Code Online (Sandbox Code Playgroud)
Xcode的警告:
'addTimeInterval:' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:27)
Run Code Online (Sandbox Code Playgroud)
我应该用什么呢?谢谢.
ken*_*ytm 93
该方法已重命名为-dateByAddingTimeInterval:.
localNotif.fireDate = [now dateByAddingTimeInterval:timeInterval];
Run Code Online (Sandbox Code Playgroud)
在Swift 2.2中:
localNotif.fireDate = now.dateByAddingTimeInterval(timeInterval)
Run Code Online (Sandbox Code Playgroud)
在Swift 3中:
localNotif.fireDate = now.addingTimeInterval(timeInterval)
// or simply
localNotif.fireDate = now + timeInterval
Run Code Online (Sandbox Code Playgroud)
Rei*_*ard 11
试试看:
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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15401 次 |
| 最近记录: |