1

这是我拥有的代码,我将日期放在应用程序徽章中。我想知道如何每天重新加载这个号码而不进入应用程序重新加载它。提前致谢!

NSDate *today = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *comp = [cal components:NSDayCalendarUnit fromDate:today];
NSInteger day = [comp day];
[UIApplication sharedApplication].applicationIconBadgeNumber = day;
4

2 回答 2

1

一种相对简单的方法是将设置徽章的代码放在后台。您可以[UIApplication beginBackgroundTaskWithExpirationHandler]为此目的使用或相关的调用。唯一的问题是这种执行有 10 分钟的限制。话虽如此,有一些技巧可以用来规避这个限制。这是一个讨论此主题的出色线程:在后台运行应用程序超过 10 分钟

于 2012-12-28T02:53:11.317 回答
0

我有以下代码:

NSDate *fireTime = [[NSDate date] addTimeInterval:3600*24];
notification.fireDate = fireTime;
notification.alertBody = @"Your Message!";
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

如果您在模拟器上进行测试,那么这可能就是您没有得到输出的原因。在设备上测试它,看看它是否工作。

于 2012-12-28T04:27:12.527 回答