当我收到这样的远程通知时,我实现了一个打开AlertView的函数:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){
var notifiAlert = UIAlertView()
var NotificationMessage : AnyObject? = userInfo["alert"]
notifiAlert.title = "TITLE"
notifiAlert.message = NotificationMessage as? String
notifiAlert.addButtonWithTitle("OK")
notifiAlert.show()
}
Run Code Online (Sandbox Code Playgroud)
但NotificationMessage总是零.
我的json有效负载如下所示:
{"aps":{"alert":"Testmessage","badge":"1"}}
Run Code Online (Sandbox Code Playgroud)
我正在使用Xcode 6,Swift和我正在为iOS8开发.我现在搜索了几个小时,但没有找到任何有用的信息.通知工作完美..如果我点击它,将打开alertview.我的问题是,我无法从userInfo中获取数据.
我实现了一个UITableViewController的搜索功能,如下所示:
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,如果我点击它,我的导航栏和我的navigationcontrollers标题就会消失.是否有解决方案来阻止这种行为(在swift中)?
没有点击:
点击: