簡體   English   中英

iOS:單擊一個通知或應用程序圖標即可處理所有uilocalnotification

[英]iOS : Handle all the uilocalnotification on click of one notification or app icon

我如何處理一個UILocalNotification單擊通知中的所有UILocalNotification (打開警報),因為蘋果單擊一個通知時會從通知中心清除其他通知...如果用戶在忽略通知中心中的通知的情況下打開應用程序,我該如何處理處理(也打開UIAlertView )嗎? 我已經在Calminder應用程序中看到了它的完美工作

您可以使用[[UIApplication sharedApplication] scheduledLocalNotifications]; 獲取所有先前安排的通知。 此方法返回一個NSArray實例,因此您可以運行for循環來處理這些:

for (UILocalNotification *notification in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
    // Handling codes goes here.
}

如果您希望通知中包含一些其他信息,則可以使用userInfo屬性。 這是一個字典,用於在通知中存儲其他信息。 您可以這樣設置:

notification.userInfo = // The dictionary goes here.

現在,您可以執行以下操作:

for (UILocalNotification *notification in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
    NSDictionary *userInfo = notification.userInfo;
    // Handling codes goes here. Now you can use the user info dictionary to
    // get what you stored into the userInfo dictionary when you are
    // initializing the user info.
}

之后,您可以獲得所有信息,並將其呈現在UIAlertView

要在應用啟動時在上面調用這些代碼,您可以使用兩種方法:

-application:didFinishLaunchingWithOptions:

要么

-applicationDidBecomeActive:

希望這可以幫助。

暫無
暫無

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

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