34

ローカル通知の作成に使用addTimeIntervalしていますが、現在は非推奨になっているようです(iOS4)。

私のコード:

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)

代わりに何を使用すればよいですか?ありがとう。

4

2 に答える 2

93

メソッドの名前がに変更されました-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
于 2010-06-16T15:50:07.897 に答える
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];
}
于 2010-11-27T12:19:04.603 に答える