gpt4 book ai didi

iphone - scheduleLocalNotification 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:09:18 30 4
gpt4 key购买 nike

当我从 dateTimePicker.date 获取时间/日期时,通知有效,但当我使用 dateFromString 触发日期时,通知无效。

代码:

-(IBAction)alarmSetButtonTapped:(id)sender {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.locale = [NSLocale systemLocale];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;

NSString *tmp = @"2012-09-05 10:19";
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

NSDate *dateFromString = [dateFormatter dateFromString: tmp];
NSLog(@"Alarm TMP %@", dateFromString);
[dateFormatter release];


[self scheduleLocalNotificationWithDate:dateFromString];
[self presentMessage:@"Alarm set"];

};

你能帮帮我吗??

编辑:

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate {

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = fireDate;
notification.alertBody = @"Time to wake up";
notification.soundName = @"clock.mp3";

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

[notification release];
}

最佳答案

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

// Set the fire date/time
[localNotification setFireDate:yourDate];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];

localNotification.applicationIconBadgeNumber=1;

// Setup alert notification
[localNotification setAlertAction:@"Open App"];
[localNotification setAlertBody:[randonQuotesDic objectForKey:@"Rajneesh"]];
[localNotification setAlertBody:@"You had set a Local Notification on this time"];

localNotification.soundName=UILocalNotificationDefaultSoundName;
[localNotification setHasAction:YES];
UIApplication *app=[UIApplication sharedApplication];
[app scheduleLocalNotification:localNotification];

关于iphone - scheduleLocalNotification 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12277334/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com