iPhone的iOS 4 addTimeInterval弃用

我使用addTimeInterval来创build本地通知,但它似乎已被弃用(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 

尝试一下:

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