我正在使用 addTimeInterval
创建本地通知,但它似乎现已弃用(iOS 4)。
我的代码:
localNotif.fireDate = [now addTimeInterval:timeInterval];
Xcode 的警告:
'addTimeInterval:' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:27)
我应该用什么来代替? 谢谢。
最佳答案
该方法已重命名为-dateByAddingTimeInterval:
.
localNotif.fireDate = [now dateByAddingTimeInterval:timeInterval];
<小时/>
在 Swift 2.2 中:
localNotif.fireDate = now.dateByAddingTimeInterval(timeInterval)
<小时/>
在 Swift 3 中:
localNotif.fireDate = now.addingTimeInterval(timeInterval)
// or simply
localNotif.fireDate = now + timeInterval
关于iPhone iOS 4 addTimeInterval 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3054914/