-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];
這一切就是這麼簡單,真的。