如何在iPhone中进行本地通知?

发布于 2024-11-03 21:25:26 字数 129 浏览 4 评论 0原文

我想在特定时间后通知用户某件事。有关于这个主题的资源吗?指南或示例代码特别有帮助。我读过很多相关网站,但它们都是关于服务器端通知,例如 Facebook 通知消息到达位置或类似的内容。我只想从 iPhone 应用程序本地触发它,而不涉及服务器。

I want to notify the user about something after some specific time. Are there any resources on this topic? Guides or sample code are particularly helpful. I have read a number of sites about it, but they are all about server side notifications like Facebook notify where if a message arrives or something like that. I just want it triggered locally from the iPhone app with no server involved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时光的容颜 2024-11-10 21:25:26

是的!您正在寻找 UILocalNotification。创建并配置它后,您可以 立即呈现安排它在某个时间点出现


换句话说:

//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];

真的,这就是全部。

Yep! You're looking for a UILocalNotification. Once you've created one and configured it, you can either present it immediately or schedule it to appear at a certain point in time.


In other words:

//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];

That's all there is to it, really.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文