gpt4 book ai didi

ios - 是否可以只从 scheduledLocalNotifications 数组中的对象获取时间?

转载 作者:行者123 更新时间:2023-11-28 20:11:40 25 4
gpt4 key购买 nike

我想向我的用户显示下一个本地通知的时间,环顾四周后我发现了 scheduledLocalNotifications,这是一个存储我的应用程序创建的所有通知的数组。

我只想获取分钟和小时,但是当我对数组中的对象执行 NSLOG 时,它会显示我的大量信息。

这是我访问的方式:

   UIApplication *meuApp = [UIApplication sharedApplication];
NSArray *arrayDeNotificacoes = [meuApp scheduledLocalNotifications];

if (arrayDeNotificacoes.count == 0) {
NSLog(@"NO");
} else {
NSLog(@"Yeap!");
NSLog(@"%@", arrayDeNotificacoes[0]);
}

这是我得到的结果:

2013-11-15 13:53:57.300 Timer V[574:70b] {fire date = Friday, November 15, 2013 at 4:53:31 PM Brasilia Summer Time, time zone = America/Sao_Paulo (GMT-2) offset -7200 (Daylight), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Friday, November 15, 2013 at 4:53:31 PM Brasilia Summer Time, user info = (null)}

那么我怎样才能只显示小时和分钟,以显示给用户呢?

最佳答案

访问通知上的 fireDate 属性:

UILocalNotification *not =  arrayDeNotificacoes[0];
NSDate *notDate = not.fireDate;

有了 NSDate,只需创建一个格式化程序来显示小时和分钟:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];

NSString *stringFromDate = [formatter stringFromDate:notDate];

关于ios - 是否可以只从 scheduledLocalNotifications 数组中的对象获取时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20005125/

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