我正在使用遠程通知來喚醒我的應用程序並有條件地觸發UILocalNotification。iOS UILocalNotification僅在應用程序未運行時發出聲音(無警報)
我發現如果這個通知是在應用程序沒有運行時觸發的,我得到的只是通知聲音(沒有警報/通知)。如果應用程序在後臺,它會按預期工作。
註冊爲遠程通知中的AppDelegate:
let settings = UIUserNotificationSettings(forTypes: (.Badge | .Sound | .Alert), categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
創建/ UILocalNotification的燒成(作爲didReceiveRemoteNotification
結果)
var notification = UILocalNotification()
notification.alertTitle = "My App"
notification.alertBody = "Hello World!"
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
據我可以從文檔告訴,通知的行爲,當該應用程序在後臺,根本不運行應該是相同的。
當系統提供本地通知時,可能會發生幾種情況,具體取決於應用程序狀態和通知類型。如果應用程序不是最前面並且可見,則系統顯示警報消息,標記應用程序並播放聲音 - 無論通知中指定了什麼內容。如果通知是警報,並且用戶點擊操作按鈕(或者,如果設備被鎖定,則拖動打開操作滑塊),則應用程序被喚醒或啓動。
來源:UILocalNotification Documentation
見識到了什麼是怎麼回事,非常感謝!
運行設置應用程序並轉到您的應用程序頁面。檢查您的應用的通知設置。 – rmaddy
我已驗證應用程序的通知設置已啓用。正如我所提到的,當應用程序處於後臺時,所有功能都可以正常工作,但不是在我明確關閉它時(通過將其滑開) – Rhinon