當在前臺應用程序,你只能得到回調,iOS不顯示警報在這種情況下,你必須自己做...
你可以這樣說:
爲「PN前景視圖」創建一個筆尖,例如:
而當你在前臺得到一個PN,你可以實例化視圖,並將其與動畫添加到一個UIWindow,代碼例如:
// init and configure your custom PN foreground view
let nib = UINib(nibName: self.nibName, bundle: NSBundle(forClass: PnForegroundView))
pnForegroundView = nib.instantiateWithOwner(nil, options: nil)[0] as! PnForegroundView
pnForegroundView.setWidth(UIScreen.width)
pnForegroundView.setHeight(63)
pnForegroundView.title = <some title from notification>
pnForegroundView.image = <some image from notification>
// add the view to the key window
let window = UIApplication.sharedApplication().keyWindow!
window.addSubview(pnForegroundView!)
// Change window level to hide the status bar
window.windowLevel = UIWindowLevelStatusBar
// Show the PN foreground view with animation:
self.pnForegroundView!.setBottom(0)
self.changeWindowLevelToHideStatusBar()
UIView.animateWithDuration(0.2) {
self.pnForegroundView!.setBottom(self.pnForegroundView!.height)
}
當然,你應該設定一個代表對於這個視圖,用戶點擊通知的情況以及用戶解除它的情況。
此外,您可以添加時間自動解僱。
最後一件事 - 取出PnForegroundView
時,你最好重置UIWindow
級別設置爲默認值,顯示在狀態欄
是啊,我知道,但我想顯示當應用程序在後臺顯示相同的警報通知 –
好友,當應用程序在後臺,仍然活動,你可以創建一個本地通知,並把它扔掉:)它看起來絕對像遠程通知,你甚至可以處理徽章計數以及:)但當用戶點擊s的通知你將得到控制在didRecieveLocalNotification方法,這是所有:) –
我已經做到了,我沒有得到橫幅警報,它只是顯示在通知中心沒有任何聲音或警報 –