我正在嘗試做一個小使者,我想顯示一條警告消息,指出除了談話本身。現在,我的警報隨處顯示,是否可以過濾它,以便它不顯示在ConversationDetailController上?如何在iOS推送通知後顯示UIAlertView,除了在一個視圖中
這是我在的appdelegate代碼
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
var mess:String?
var displayName:String?
if let result = userInfo["aps"] as? NSDictionary {
if let alert = result["alert"] as? String {
mess = alert
if let extra = userInfo["extra"] as? NSDictionary
{
if let name = extra["displayName"] as? String
{
displayName = name
var alert = UIAlertView(title: "You have a new message from \(displayName!)", message: mess, delegate: nil, cancelButtonTitle: "OK")
alert.show()
}
}
NSNotificationCenter.defaultCenter().postNotificationName("newMessageReceived", object: nil)
}
}
}
你的視圖控制器是如何呈現的?對你的問題最簡單的解決方案是檢查self.window.rootViewController,但如果你使用容器(如UITabBarController或UINavigationController),這將不是你正在尋找的viewController – chedabob
My ConversationDetailTableViewController嵌入在UINavigationController不幸的是:/ –