AppDelegate:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: NSDictionary) {
let aps: NSDictionary = userInfo.objectForKey("aps") as NSDictionary
UpdatesViewController().newArticle(aps)
}
UpdatesViewController:
class UpdatesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate {
func newArticle(userInfo: NSDictionary) {
let title: NSString = userInfo["alert"] as NSString
UIAlertView(title: "New update", message: title, delegate: self, cancelButtonTitle: "Dismiss", otherButtonTitles: "Read more").show()
}
func alertView(alertView: UIAlertView, willDismissWithButtonIndex buttonIndex: Int) {
println(buttonIndex)
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
println(buttonIndex)
}
}
发送推送通知时,我收到来自APNS的正确消息的UIAlertView
。问题是,当在UIAlertView
中按下两个按钮中的任何一个按钮时,不会通过println
记录按下。
有什么想法吗?
答案 0 :(得分:1)
从iOS8 UIAlertView
代表不推荐使用。
请改用UIAlertViewController
。
答案 1 :(得分:1)
UIAlertView
已弃用。请改为使用UIAlertController
preferredStyle
代替UIAlertControllerStyleAlert
。
//示例代码显示警告
let alertController = UIAlertController(title: "Default Style", message: "A standard alert.", preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { enter code here }