【发布时间】:2012-01-18 22:51:39
【问题描述】:
我编写了一个应用程序,允许用户在 UITextField 中输入数据,其中一个允许他们输入特定日期。我试图在距离日期 15 小时后在 iPhone 通知中心显示警报,即使应用程序根本没有运行。
编辑:新代码-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMdd"];
NSDate *eventDate=[dateFormatter dateFromString:eventDateField.text];
localNotif.fireDate = [eventDate dateByAddingTimeInterval:-15*60*60];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Event Tomorrow!";
localNotif.alertAction = @"Show me";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotif];
}
【问题讨论】:
-
抱歉有点苛刻,但您缺少一些非常基本(和关键)的基础知识。帮自己一个忙,学习它们;它不会花费很长时间,最终会为您节省大量时间和挫败感。我可以推荐的一本非常好的书是iOS Programming: The Big Nerd Ranch Guide。它写得很好,涵盖了基础知识(也特别是您所询问的内容),并包含很好的示例。帮自己一个忙,得到它,阅读它,做练习。不会花很长时间,但会很有帮助。
-
谢谢你,fzwo,是的,我在这里确实有点超前了。我今天会研究那本书,谢谢!
标签: iphone xcode notifications nsdate