【发布时间】:2018-12-31 12:19:32
【问题描述】:
我正在尝试处理来自特定视图控制器的远程通知。我已经设置了我的应用程序,因此当我推送远程通知时,某个视图控制器会在 ImageView 中显示特定图像,但是如果不再次推送相同的控制器,我就无法更改图像。一旦呈现视图控制器,我正在尝试从另一个远程通知更改 ImageView 的图像。我实现这一点的想法是创建一种方法来从刚刚呈现的视图控制器的文件中处理远程通知,因此远程通知可以编辑 ImageView 的图像。这就是我在 AppDelegate 中呈现视图控制器的方式:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let data = userInfo["showiMac"] as? [String: String], let iMacConfig = data["iMacConfig"] {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootTabBarController = self.window?.rootViewController as! UITabBarController
let firstNavigationController = storyboard.instantiateViewController(withIdentifier: "initialVC1") as! UINavigationController
rootTabBarController.viewControllers![0] = firstNavigationController
//the viewController to present
let viewController = storyboard.instantiateViewController(withIdentifier: "configureiMac") as! ConfigureiMacViewController
// present VC
firstNavigationController.pushViewController(viewController, animated: true, completion: {
viewController.image = UIImage(named: "iMac" + iMacConfig)
})
completionHandler(.noData)
}
}
这是在我的视图控制器中声明图像的方式:
var image: UIImage!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = image
}
【问题讨论】:
-
请添加包括didReceiveRemoteNotification在内的周边代码...
-
我刚刚编辑了帖子以包含我的整个 didReceiveRemoteNotification 方法。
-
既然你设置了viewController.image,你能说明这个变量是如何在视图控制器中声明的吗?
-
当然。再次更新了帖子。感谢您抽出宝贵时间帮助我。