【发布时间】:2011-04-30 05:24:57
【问题描述】:
我想在特定时间后通知用户某事。有没有关于这个主题的资源?指南或示例代码特别有用。我已经阅读了很多关于它的网站,但它们都是关于服务器端通知的,比如 Facebook 通知消息到达的位置或类似的东西。我只希望它在不涉及服务器的情况下从 iPhone 应用程序本地触发。
【问题讨论】:
标签: iphone notifications local apple-push-notifications
我想在特定时间后通知用户某事。有没有关于这个主题的资源?指南或示例代码特别有用。我已经阅读了很多关于它的网站,但它们都是关于服务器端通知的,比如 Facebook 通知消息到达的位置或类似的东西。我只希望它在不涉及服务器的情况下从 iPhone 应用程序本地触发。
【问题讨论】:
标签: iphone notifications local apple-push-notifications
是的!您正在寻找UILocalNotification。创建并配置后,您可以在某个时间点present it immediately 或schedule it to appear。
换句话说:
//create the notification
UILocalNotification *notification = [[UILocalNotification alloc] init];
//configure it (this sets the message to be displayed)
[notification setAlertBody:@"This is my local notification!"];
//the notification will show up in 60 seconds
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:60]];
//queue up the notification
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
//release the object we no longer care about
[notification release];
这就是它的全部内容,真的。
【讨论】: