簡體   English   中英

如何在 iPhone 中本地通知?

[英]How to locally notify in iPhone?

我想在特定時間后通知用戶某些事情。 有沒有關於這個主題的資源? 指南或示例代碼特別有用。 我已經閱讀了許多有關它的網站,但它們都是關於服務器端通知的,例如 Facebook 通知消息到達的位置或類似的東西。 我只希望它在不涉及服務器的情況下從 iPhone 應用程序本地觸發。

是的! 您正在尋找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];

這就是它的全部,真的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM