開発中のアプリにローカル通知を追加する作業を行っています。2013 年 4 月 30 日ニューヨーク/東部時間の午後 11 時に通知を 1 つだけ設定しています。どうすればいいですか?複数の方法を試しましたが、どれも正しく機能しませんでした。これは私が現在使用しているものです(動作しません):
- (void)applicationDidEnterBackground:(UIApplication *)application
{
if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults]
objectForKey:@"setNotify"]]) {
[[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"setNotify"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSString *str = [NSString stringWithFormat:@"2013-04-23T18:22:00"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss'"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"US/Eastern"]];
NSDate *dte = [dateFormat dateFromString:str];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[cal setTimeZone:[NSTimeZone timeZoneWithName:@"US/Eastern"]];
UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc]
init];
if (notifyAlarm)
{
notifyAlarm.fireDate = dte;
notifyAlarm.timeZone = [NSTimeZone timeZoneWithName:@"US/Eastern"];
notifyAlarm.repeatInterval = 0;
notifyAlarm.soundName = @"trumpet.m4a";
notifyAlarm.alertBody = @"Message";
[app scheduleLocalNotification:notifyAlarm];
}
}
}