-1
我想在某些特定时间后通知用户有关某些事情。这个话题有没有资源?指南或示例代码特别有用。我已经阅读了许多有关它的网站,但它们都是关于像Facebook这样的服务器端通知,如果消息到达或者类似的地方通知。我只是希望它在没有涉及服务器的情况下从iPhone应用程序本地触发。如何在iPhone上进行本地通知?
我想在某些特定时间后通知用户有关某些事情。这个话题有没有资源?指南或示例代码特别有用。我已经阅读了许多有关它的网站,但它们都是关于像Facebook这样的服务器端通知,如果消息到达或者类似的地方通知。我只是希望它在没有涉及服务器的情况下从iPhone应用程序本地触发。如何在iPhone上进行本地通知?
是的!您正在寻找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];
这一切就是这么简单,真的。