iPhone iOS 4 addTimeInterval 已弃用

标签 iphone xcode nsdate ios4

我正在使用 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/

相关文章:

objective-c - iphone sdk - Itunes 连接如何更改设备要求?

iphone - 在不同上下文中非法尝试在对象之间建立关系..为什么会出现此错误?

Xcode 8/Swift 3 中的 iOS 异步单元测试(waitForExpectations 失败)

objective-c - Cocoa - 计算两个日期之间的工作日

ios - 从当前日期创建 NSDate 不正确

ios - 根据 iPhone 设置将时间转换为字符串格式 (13 :00 vs 1:00PM) in Swift

iphone - Adobe AIR for iPhone应用程序商店?

iphone - 有没有办法判断用户打电话时是否正在使用您的应用程序?

iphone - UICollectionView willDisplayCell 委托(delegate)方法?

ios - 这是使用谷歌地图进行反向地理编码的最佳实践