简体   繁体   English

当应用程序激活时刷新Parse.com数据

[英]Refreshing Parse.com data when the app becomes active

[Edited with solution below] [使用以下解决方案编辑]

I want to call a Parse.com query whenever the app becomes active, so that if it's brought up from the foreground, a new set a data will be called. 我想在应用程序处于活动状态时调用Parse.com查询,以便从前台调出应用程序时,将调用一个新的数据集。

I realize there is a method for this in the AppDelegate 我意识到AppDelegate中有一种解决方法

- (void)applicationDidBecomeActive:(UIApplication *)application {

}

But I want to know how I can put the query information obtained in my AppDelegate and put it in my ViewController where I can display the information. 但是我想知道如何将在AppDelegate中获得的查询信息放入我的ViewController中,以便在其中显示信息。

Any ideas on what I might do? 关于我可能会做什么的任何想法? Or if there is another way to make the query when the app becomes active? 还是在应用激活时还有另一种查询方法? Thanks. 谢谢。

So here is what I came up with. 这就是我的想法。 I had my method (called getData) in the ViewController, and in the viewDidLoad method, I inserted this code 我在ViewController中有我的方法(称为getData),并且在viewDidLoad方法中插入了此代码

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getData)

 name:UIApplicationDidBecomeActiveNotification object:nil];

And now it works just as I had hoped. 现在,它按我希望的那样工作。 Thanks! 谢谢!

This is a really broad question, but what you can do is you can post a notification and make your view controller listen to it. 这是一个非常广泛的问题,但是您可以做的是可以发布通知并使视图控制器侦听该通知。

Then after your app re enter from background, you can post the notification and in the observer method that you implemented in the view controller, you can pull the data from Parse. 然后,当您的应用从后台重新进入后,您可以发布通知,并在视图控制器中实现的观察者方法中,可以从Parse中提取数据。

See this question to understand the sequence of the method calls. 请参阅此问题以了解方法调用的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM