簡體   English   中英

當應用程序處於后台時,UILocalNotification不會顯示在通知中心中

[英]UILocalNotification not showing up in Notification Center when app is in background

我有一個注冊為在background運行的GPS應用程序。 完成流程后,我還將顯示UILocalNotification 這會正確顯示,並且如果該應用已打開,那么它還會顯示在Notification Center (從頂部向下滑動)。 但是,如果我在應用程序處於后台或屏幕鎖定時調用UILocalNotification ,我會收到通知,但不會在Notification Center顯示。

我在我的應用程序委托中正確注冊了通知(iOS 5錯誤解決方法):

// Register for notifications
    [[UIApplication sharedApplication]registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge |
     UIRemoteNotificationTypeAlert |
     UIRemoteNotificationTypeSound];

呼叫通知:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.alertBody = msg;
localNotif.alertAction = NSLocalizedString(@"View", nil);
localNotif.soundName = @"alert.caf";
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];

這是錯誤嗎? 為什么僅在我的應用程序打開時(即使向用戶顯示通知),它才會顯示在Notification Center

您是否還在使用推送通知? 我相信沒有必要調用registerForRemoteNotificationTypes:如果僅使用本地。

在這里檢查

從您發布的代碼的外觀來看,該代碼看起來好像不會在后台運行。 看起來您正在嘗試在后台出現偶數時顯示本地通知。 你不可以做這個。 本應在應用程序運行時安排本地通知,以在以后應用程序不運行時關閉,然后即使應用程序關閉,它們也會觸發。 您需要使用推送通知。 在此處查看Apple的文檔

編輯:您的應用是否在設置中啟用了通知中心?

您是否已將UIBackgroundModes鍵添加到Info.plist文件中?

您需要將UIBackgroundModes密鑰設置為location。

暫無
暫無

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

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