iPhone iOS 4 addTimeInterval 已弃用

发布于 2024-09-06 01:54:53 字数 418 浏览 2 评论 0 原文

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

我应该使用什么代替? 谢谢。

I'm using addTimeInterval for creating local notification but it seems that it is now deprecated (iOS 4).

My code:

localNotif.fireDate = [now addTimeInterval:timeInterval];

Xcode's warning:

'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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

治碍 2024-09-13 01:54:53

该方法已重命名为 -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

The method has been renamed to -dateByAddingTimeInterval:.

localNotif.fireDate = [now dateByAddingTimeInterval:timeInterval];

In Swift 2.2:

localNotif.fireDate = now.dateByAddingTimeInterval(timeInterval)

In Swift 3:

localNotif.fireDate = now.addingTimeInterval(timeInterval)
// or simply
localNotif.fireDate = now + timeInterval
梦醒时光 2024-09-13 01:54:53

尝试一下:

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];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文