【发布时间】:2017-10-12 16:46:18
【问题描述】:
我在 App Delegate 中收到一条通知,其中包含数据中的问题(userInfo 变量),我需要将此字符串传递给名为“问题”的视图控制器。我希望这个字符串显示在问题视图控制器中的这个变量 @IBOutlet weak var question: UILabel! 中。
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
let storyboard = UIStoryboard(name:"Main", bundle:nil)
let question_view = storyboard.instantiateViewController(withIdentifier: "Question")
window?.rootViewController = question_view
completionHandler()
}
如何将数据传递给视图控制器?我试图从那里访问变量,但我没有工作。谢谢!
【问题讨论】:
标签: ios swift uiviewcontroller notifications appdelegate