[英]Present viewController over rootViewController when a notification is tapped
[英]Present ViewController on notification alertaction button tapped
我想在用戶點擊橫幅通知或alertnotification上的“確定”時顯示特定的視圖控制器。 每當應用收到使用此方法發出的voip推送通知時,我都會收到通知:
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
let data = payload.dictionaryPayload
let aps = data["aps"] as! [String: AnyObject]
let alert = aps["alert"] as! [String: AnyObject]
let notification = UILocalNotification()
//setup the notification
notification.alertBody = alert["body"] as? String
notification.alertTitle = alert["title"] as? String
notification.soundName = aps["sound"] as? String
notification.alertAction = alert["action-loc-key"] as! String
//show the notification
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
如何將操作添加到輕擊橫幅或notification.alertAction?
實現以下方法:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
print("applicationDidReceiveLocalNotification")
}
在打開應用程序時,通過點擊通知橫幅將調用此方法。在此方法中,您可以顯示要打開的ViewController。
您需要將本地通知與交互式通知一起使用。
Apple允許我們在ios8 +中使用交互式通知。使用此功能,您可以在單擊使用交互式通知功能創建的按鈕時顯示視圖控制器。
作為參考,您可以使用此http://www.appcoda.com/local-notifications-ios8/和如何實現交互式通知ios8,並且此功能還有一些其他有用的教程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.