[英]Parse.com app goes forward before i get the value I want (async) iOS
I use a query FindObjectsInBackgroundWithBlock (assync) to get a value from webservice... I want that value on the appdelegate before the app loads. 我使用查询FindObjectsInBackgroundWithBlock(assync)从webservice获取值...我想在应用程序加载之前在appdelegate上使用该值。 I'm trying do it but he still load the app before check the webservices to get the value.
我正在尝试这样做,但他仍然加载应用程序,然后检查webservices以获取值。 How can I handle it?
我该怎么处理? I already tried with a NSTimer..
我已经尝试过NSTimer ..
I called this method in -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
: 我在
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
调用了这个方法-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
:
-(void)checkUserVersion{
PFQuery *query = [PFQuery queryWithClassName:@"sqliteversion"]; //1
// NSNumber *n=databaseVersion;
[query whereKey:@"user_version" equalTo:[NSNumber numberWithInt:[databaseVersion integerValue]]];//2
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {//4
if (!error && [objects count]>0) {
for (PFObject *object in objects) {
valor1=[[object objectForKey:@"Value"]intValue];
user_version=[NSNumber numberWithInt:valor1];
}
}
}];
}
You can't run any code in your app before it finishes launching. 在完成启动之前,您无法在应用中运行任何代码。 If the value is critical for your app to begin working you'll have to show a "waiting for data" message.
如果该值对您的应用开始工作至关重要,则必须显示“等待数据”消息。
You may want to evaluate why it's necessary to have this information from Parse.com before launch. 您可能想要评估为什么在发布之前必须从Parse.com获取此信息。 Also, it can mean many things to say "before launch", and there are many solutions that don't involve doing "everything" before the first view is attached to the window and shown.
此外,它可能意味着许多事情要说“在发布之前”,并且有许多解决方案不涉及在第一个视图附加到窗口并显示之前执行“一切”。
That said...run the PFQuery fetch in the foreground. 那就是说...在前台运行PFQuery fetch。 Doing this will block execution of the rest of your code, though.
但是,执行此操作将阻止执行其余代码。 Instead of
findObjectsInBackground
just use the findObjects
method of PFQuery. 而不是
findObjectsInBackground
只使用PFQuery的findObjects
方法。 I would advise against doing this though, and instead try to find out a way to wait for the query to return while the app is already loaded. 我建议不要这样做,而是尝试找到一种方法,等待查询返回,同时应用程序已加载。 Maybe you could suspend user interaction but display a loading indicator or something?
也许你可以暂停用户交互,但显示一个加载指示器或什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.